Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libheif support #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

ericdevries
Copy link

Adds libheif to the build process

@shanecowherd
Copy link

+1 Works great!

@makersm
Copy link

makersm commented Jun 4, 2020

👍 It works! Thanks a lot

@vasilenko93
Copy link

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

Copy link

@shanecowherd shanecowherd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works, been using it in production for several weeks.

@TorsteinHonsi
Copy link

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

@ericdevries
Copy link
Author

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

@ericdevries
Copy link
Author

Now with lcms2 built into it as well

@mcxemic
Copy link

mcxemic commented Apr 1, 2021

@ericdevries do you have plans to merge this update?

@ericdevries
Copy link
Author

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

@readonlychild
Copy link

readonlychild commented Oct 22, 2021

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

@nicolae536
Copy link

nicolae536 commented Mar 22, 2022

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.

@dhardiker
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants