imagemagick-aws-lambda-2 icon indicating copy to clipboard operation
imagemagick-aws-lambda-2 copied to clipboard

Add libheif support

Open ericdevries opened this issue 5 years ago • 11 comments

Adds libheif to the build process

ericdevries avatar Mar 13 '20 08:03 ericdevries

+1 Works great!

shanecowherd avatar May 01 '20 16:05 shanecowherd

👍 It works! Thanks a lot

makersm avatar Jun 04 '20 07:06 makersm

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 :)

vasilenko93 avatar Jun 26 '20 20:06 vasilenko93

@ericdevries Did you consider adding AVIF support? I tried but failed. Would be great to get help with that. See #30.

TorsteinHonsi avatar Oct 22 '20 11:10 TorsteinHonsi

I have not, but if you have made any progress I am glad to help out getting it to work

ericdevries avatar Oct 25 '20 09:10 ericdevries

Now with lcms2 built into it as well

ericdevries avatar Mar 26 '21 12:03 ericdevries

@ericdevries do you have plans to merge this update?

mcxemic avatar Apr 01 '21 11:04 mcxemic

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

ericdevries avatar Apr 28 '21 15:04 ericdevries

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

readonlychild avatar Oct 22 '21 15:10 readonlychild

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.

nicolae536 avatar Mar 22 '22 16:03 nicolae536

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.

dhardiker avatar Oct 01 '22 23:10 dhardiker