imagemagick-aws-lambda-2
imagemagick-aws-lambda-2 copied to clipboard
Add libheif support
Adds libheif to the build process
+1 Works great!
👍 It works! Thanks a lot
Hello, is there a reason this PR was not merged into the master branch? We use imagemagick-aws-lambda-2 as part of our Lamba function to convert user uploaded images and a sizable portion of the user base uploads heic formats (from iPhone camera I believe). We implemented the changes done in this PR and it works great :)
@ericdevries Did you consider adding AVIF support? I tried but failed. Would be great to get help with that. See #30.
I have not, but if you have made any progress I am glad to help out getting it to work
Now with lcms2 built into it as well
@ericdevries do you have plans to merge this update?
Unfortunately the owner of the repository has indicated that he wants to keep the layer as small as possible and will not merge in any of the outstanding pull requests. Perhaps we should create an "official" fork that merges in the extra features for those who do want more functionality at the expense of a larger layer
Hi @ericdevries
Have you used your build as a layer in AWS Lambda?
While it builds the resulting magick -list format will have heif as r-- and avif as *---
And putting other things in (to achive avif*rw-) then building puts me in a place where lambda will start to do
shared library XYZ not found, starting with libheif.so.0
Did anyone had any problems with .heif files ? 🤔 I created a lambda and added a layer pointing to this it seems to convert fine the .heic images but I have this image https://s3.eu-central-1.amazonaws.com/houzy.test-heic-convert-lambda/sample1+(2).heif
Which seems to not work 🤔 . Maybe I'm missing something. This is the lambda code for reference:
const gm = require('gm').subClass({ imageMagick: true });
const AWS = require("aws-sdk");
AWS.config.update({
region: 'eu-central-1'
});
function gmToBuffer(data) {
return new Promise((resolve, reject) => {
data.stream((err, stdout, stderr) => {
if (err) { return reject(err) }
const chunks = []
stdout.on('data', (chunk) => { chunks.push(chunk) });
// these are 'once' because they can and do fire multiple times for multiple errors,
// but this is a promise so you'll have to deal with them one at a time
stdout.once('end', () => { resolve({
buffer: Buffer.concat(chunks),
isEmpty: chunks.length === 0,
}); });
stderr.once('error', (data) => { reject(String(data)) });
})
});
};
// convert HEIC to JPEG
exports.handler = async (event, context, callback) => {
const bucketName = event.bucketName;
const inputFileKey = event.inputFileKey;
const outputFileKey = event.outputFileKey;
try {
const s3 = new AWS.S3({ params: { Bucket: bucketName } });
const readFileStream = s3.getObject({ Key: inputFileKey }).createReadStream();
const {buffer, isEmpty} = await gmToBuffer(gm(readFileStream).setFormat('jpeg'));
if (isEmpty) {
throw new Error(`Failed to convert image: ${inputFileKey} buffer is empty`);
}
const uploadParams = {
ACL: 'public-read',
Body: buffer,
ContentType: 'image/jpeg',
Key: outputFileKey,
Bucket: bucketName
};
await s3.upload(uploadParams).promise();
} catch (error) {
console.error(error);
throw new Error(`${error.code} ${error.message} ${error.data}`);
}
};
And on top of this I added a layer containing this repo. From what i read heic / heif are interchangeable but for the image above it doesn't seem to work. Is there a dependency missing or maybe that file has problems 🤔 Can somebody give a second opinion would be very appreciated.
Unfortunately the owner of the repository has indicated that he wants to keep the layer as small as possible and will not merge in any of the outstanding pull requests. Perhaps we should create an "official" fork that merges in the extra features for those who do want more functionality at the expense of a larger layer
Or perhaps support these additional common formats as compile time flags, making them easier to enable optionally. Hopefully that would avoid forking what is such a useful resource.