catdad-experiments / heic-convert Goto Github PK
View Code? Open in Web Editor NEWπ€³ convert heic/heif images to jpeg and png
π€³ convert heic/heif images to jpeg and png
is there any repo/composer for php?
Hi there,
I'd like to report an issue. After installing 'heic-convert' in my Vue project and attempting to import it into my components, I encountered the following error: "Uncaught TypeError: util.inherits is not a function." Could you please provide insights into the cause of this error?
Can you add typescript support?
Before deciding to convert HEIC we need to first determine if the image is HEIC.
I could check mime, etc..but it seems your code already has an isHEIC method but it's not exported.
Currently you just throw an exception if image is not HEIC. And that exception is of type TypeError and has a string.
It would be great if you either expose isHEIC method or throw a more specific exception. Currently I'm catching the exception and parsing the message to determine if image is not HEIC, which is a brittle approach to determine if image is HEIC.
With a multiple image heic
TypeError: Cannot read property 'slice' of undefined
at uint8ArrayUtf8ByteString (/Users/jeremie/Desktop/dossier sans titre/node_modules/heic-decode/index.js:4:39)
at isHeic (/Users/jeremie/Desktop/dossier sans titre/node_modules/heic-decode/index.js:10:22)
at decodeBuffer (/Users/jeremie/Desktop/dossier sans titre/node_modules/heic-decode/index.js:47:8)
at module.exports (/Users/jeremie/Desktop/dossier sans titre/node_modules/heic-decode/index.js:69:46)
at convert (/Users/jeremie/Desktop/dossier sans titre/node_modules/heic-convert/index.js:39:25)
at module.exports (/Users/jeremie/Desktop/dossier sans titre/node_modules/heic-convert/index.js:56:70)
at init (/Users/jeremie/Desktop/dossier sans titre/heicextract.js:21:26)
I am trying to convert heic image into jpeg.
1 => take image from s3 bucket.
2 => convert image ( quality => 0.35)
3 => save converted image on s3 bucket.
it takes almost 20+ sec for the whole process.
is there any way to reduce this time?
Could not parse HEIF fileο½
code:heif_error_code_heif_error_invalid_input
sub code:heif sub error code heif sub error end of data
}
can I use this in react native?
Hi @catdad ππΌ πββ¬
Human-dad here. Thanks for writing these modules. ππΌ
I"m trying to use heic-convert
to convert a bunch of files exported from Google Photos with Google Takeout, but getting an error input buffer is not a HEIC image
.
I created a repro repo here: https://github.com/zeke/heic-convert-test
Am I missing something obvious?
$ file flower.heic
flower.heic: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=10, manufacturer=Apple, model=iPhone SE (2nd generation), orientation=upper-right, xresolution=167, yresolution=175, resolutionunit=2, software=15.1, datetime=2022:01:13 13:23:04, hostcomputer=iPhone SE (2nd generation)TIFF image data, big-endian, direntries=10, manufacturer=Apple, model=iPhone SE (2nd generation), orientation=upper-right, xresolution=167, yresolution=175, resolutionunit=2, software=15.1, datetime=2022:01:13 13:23:04, hostcomputer=iPhone SE (2nd generation)], baseline, precision 8, 4032x3024, components 3
{
inputBuffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff e1 17 0a 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 0a 01 0f 00 02 00 00 00 06 00 00 ... 2150157 more bytes>
}
TypeError: input buffer is not a HEIC image
at decodeBuffer (/Users/z/Desktop/heic-convert-test/node_modules/heic-decode/index.js:48:11)
at module.exports (/Users/z/Desktop/heic-convert-test/node_modules/heic-decode/index.js:69:46)
at convert (/Users/z/Desktop/heic-convert-test/node_modules/heic-convert/index.js:39:25)
at module.exports (/Users/z/Desktop/heic-convert-test/node_modules/heic-convert/index.js:56:70)
at /Users/z/Desktop/heic-convert-test/index.js:9:30
Hi
In one of the examples you give in the manual it is assumed that one single heic file contains many single pictures.
I have following use case:
IΒ΄m javascript beginner and donΒ΄t know how to solve this since using your script only one single heic file is converted into multiple jpec files.
Any idea how to solve this by adapting your example script Convert the main image in a HEIC to PNG ?
I look forward to your reply.
Thanks in advance.
Best
Sam
@catdad Thank you so much for this contribution! I was unfortunately struggling to get this working with our framework ParsePlatform https://parseplatform.org/
We get our files as based64 encoded strings. After converting them to a binary buffer I get this error
Could not parse HEIF file { code: ctor {}, subcode: ctor {} }
[]
ERROR: Error: HEIF image not found
at decodeBuffer (/Users/josephhanson/projects/app/node_modules/heic-decode/index.js:57:11)
The code snippet I am using to reproduce this is
const mediaData = await media.source.getData(); // returns a base64 encoded string of the HEIC image
const inputBuffer = Buffer.from(mediaData, 'base64');
const outputBuffer = await convert({
buffer: Buffer.from(inputBuffer.toString('binary')),
format: 'JPEG',
quality: 1,
});
Do you happen to have an example of using this library with a base64 encoded image?
Hi, was wondering if this library was meant for Server-Side usage or Browser usage? Thanks!
I'm getting this error from version 2.
I'm trying to use this lib but keep getting this error:
BindingError {
name: 'BindingError',
message: 'Cannot pass non-string to std::string',
stack: 'BindingError: Cannot pass non-string to std::string\n' +
' at BindingError.<anonymous> (/Users/hisham/src/ess-app/packages/cli/node_modules/libheif-js/libheif/libheif.js:1:178858)\n' +
' at new BindingError (eval at createNamedFunction (/Users/hisham/src/ess-app/packages/cli/node_modules/libheif-js/libheif/libheif.js:18:11916), <anonymous>:4:34)\n' +
' at throwBindingError (/Users/hisham/src/ess-app/packages/cli/node_modules/libheif-js/libheif/libheif.js:1:182383)\n' +
' at Object.toWireType (/Users/hisham/src/ess-app/packages/cli/node_modules/libheif-js/libheif/libheif.js:1:209812)\n' +
' at Object.heif_context_read_from_memory (eval at new_ (/Users/hisham/src/ess-app/packages/cli/node_modules/libheif-js/libheif/libheif.js:1:203780), <anonymous>:8:26)\n' +
' at HeifDecoder.decode (/Users/hisham/src/ess-app/packages/cli/node_modules/libheif-js/libheif/libheif.js:18:10575)\n' +
' at decodeBuffer (/Users/hisham/src/ess-app/packages/cli/node_modules/heic-decode/index.js:52:24)\n' +
' at module.exports (/Users/hisham/src/ess-app/packages/cli/node_modules/heic-decode/index.js:69:46)\n' +
' at convert (/Users/hisham/src/ess-app/packages/cli/node_modules/heic-convert/index.js:39:25)\n' +
' at module.exports (/Users/hisham/src/ess-app/packages/cli/node_modules/heic-convert/index.js:56:70)\n' +
' at ImageService.convertHEICToJpeg (/Users/hisham/src/ess-app/packages/cli/src/utils/image.service.ts:26:22)\n' +
' at Object.<anonymous> (/Users/hisham/src/ess-app/packages/cli/src/utils/image.service.test.ts:14:39)\n' +
' at Object.asyncJestTest (/Users/hisham/src/ess-app/packages/cli/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:106:37)\n' +
' at /Users/hisham/src/ess-app/packages/cli/node_modules/jest-jasmine2/build/queueRunner.js:45:12\n' +
' at new Promise (<anonymous>)\n' +
' at mapper (/Users/hisham/src/ess-app/packages/cli/node_modules/jest-jasmine2/build/queueRunner.js:28:19)\n' +
' at /Users/hisham/src/ess-app/packages/cli/node_modules/jest-jasmine2/build/queueRunner.js:75:41\n' +
' at processTicksAndRejections (internal/process/task_queues.js:97:5)'
}
Hi Kiril,
I see in the readme that it is possible to convert multiple images. However, does heic-convert also have a way to access embedded auxiliary images (e.g., Portrait photo depth map) as the non-JS version of heif-convert (the example app from libheif repo) does?
In other issues I saw you mention that heic-convert is based on the JS version of libheif. When checking heif_enscripten.h I see some references to auxiliary images, but I can't tell if the methods are actually implemented.
Many thanks in advance.
Thank you so much for this awesome work finally i solved HEIC issue for my react native app :)
hello
im trying to add heic file in my next js 14 app with formData on my windows machine using this code
const data = await req.formData();
const kk = data.get("kk") as File;
const kk_buffer = kk && kk instanceof Blob ? await kk.arrayBuffer() : undefined;
if (kk.name.split(".")[1] === "heic" || kk.name.split(".")[1] === "heif") {
const kk_converted = await convert({
buffer: kk_buffer,
format: "JPEG",
});
console.log("π ~ kk_converted:", kk_converted)
}
and i got error like this: Spread syntax requires ...iterable[Symbol.iterator] to be a function
is this because im upload from my windows machine?
Hi,
converting a HEIC image shot on an iPhone 13 to either a JPEG or PNG results into the image being flipped (wrongly rotated) for some images.
Looking at the EXIF data of the converted JPEG it looks like it just sets the orientation to 3 for every image.
I'll also attach the test HEIC file if you want to debug it (it's zipped because Github does not allow HEIC files)
Hi,
could you please Update jpeg-js
to the latest version 0.4.4?
best regards
Matthias
Vulnerability found
{
"metadata": null,
"vulnerable_versions": "<0.4.4",
"module_name": "jpeg-js",
"severity": "moderate",
"github_advisory_id": "GHSA-xvf7-4v9q-58w6",
"cves": [
"CVE-2022-25851"
],
"access": "public",
"patched_versions": ">=0.4.4",
"cvss": {
"score": 0,
"vectorString": null
},
"updated": "2022-06-17T01:00:49.000Z",
"recommendation": "Upgrade to version 0.4.4 or later",
"cwe": [
"CWE-835"
],
"found_by": null,
"deleted": null,
"id": 1070904,
"references": "- https://nvd.nist.gov/vuln/detail/CVE-2022-25851\n- https://github.com/jpeg-js/jpeg-js/issues/105\n- https://github.com/jpeg-js/jpeg-js/pull/106/\n- https://github.com/jpeg-js/jpeg-js/commit/9ccd35fb5f55a6c4f1902ac5b0f270f675750c27\n- https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSNPM-2860295\n- https://snyk.io/vuln/SNYK-JS-JPEGJS-2859218\n- https://github.com/advisories/GHSA-xvf7-4v9q-58w6",
"created": "2022-06-11T00:00:17.000Z",
"reported_by": null,
"title": "Infinite loop in jpeg-js",
"npm_advisory_id": null,
"overview": "The package jpeg-js before 0.4.4 are vulnerable to Denial of Service (DoS) where a particular piece of input will cause to enter an infinite loop and never return.",
"url": "https://github.com/advisories/GHSA-xvf7-4v9q-58w6"
}
Been trying to use heic-convert with an image that is passed as base64 string. Always getting TypeError: input buffer is not a HEIC image
.
imagemagick:
~/Downloads/IMG_7316.HEIC HEIC 3024x4032 3024x4032+0+0 8-bit sRGB 2.32526MiB 0.020u 0:00.008
file command:
~/Downloads/IMG_7316.HEIC: ISO Media, HEIF Image HEVC Main or Main Still Picture Profile
This online base64 decoder also identifies the image as HEIC.
Code
const inputBuffer = Buffer.from(heicBase64String, 'base64');
const outputBuffer: Buffer = await convert({
buffer: inputBuffer,
format: 'JPEG', // output format
quality: 0.85, // the jpeg compression quality, between 0 and 1
});
I have a question: does the HEIC->JPG conversion retain the image metadata?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.