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

Use Imagick class #6754

Draft
wants to merge 7 commits into
base: v5/develop
Choose a base branch
from
Draft

Use Imagick class #6754

wants to merge 7 commits into from

Conversation

distantnative
Copy link
Member

@distantnative distantnative commented Oct 16, 2024

Description

  • Help needed: Cannot figure out why ICC profile isn't preserved
  • Unit tests methods that change the Imagick object
  • Set CLI back to use latest ubuntu version

Summary of changes

  • New Imagick class for imagick darkroom driver
  • Old CLI version still available as im ( ImageMagick class)

Changelog

Enhancements

  • New imagick thumbs driver, using the Imagick class instead of command line
    • imagick thumbs driver does not respect bin option

Deprecated

  • im driver option, use imagick instead

Ready?

  • In-code documentation (wherever needed)
  • Unit tests for fixed bug/feature
  • Tests and CI checks all pass

For review team

  • Add lab and/or sandbox examples (wherever helpful)
  • Add changes & docs to release notes draft in Notion

@afbora
Copy link
Member

afbora commented Oct 16, 2024

I don't have any idea about IM. I've run unit tests. Getting following error for all provider for ::testKeepColorProfileStripMeta()

identify: unknown image property "%[profile:icc]" @ warning/property.c/InterpretImageProperties/4238.

@afbora afbora removed their assignment Oct 23, 2024
@distantnative distantnative added the needs: help 🙏 Really needs some help on this label Jan 18, 2025
@bastianallgeier
Copy link
Member

It's no help with the todos (sorry about that) but I was just thinking if we maybe could change the driver name to "imagick" for this and keep the old "im" driver? Then it wouldn't be a breaking change, but more important: the preferred name would be a lot better.

@rasteiner
Copy link
Contributor

  • Help needed: Cannot figure out why ICC profile isn't preserved

I have some doubts about calling stripImage() together with profileImage().

A short test for demonstration (not a solution):

function doTest(string $file, string $ext) {
    $image = new Imagick($file);

    // get the ICC profile before stripping
    $profiles = $image->getImageProfiles('icc', true);

    // strip all metadata
    $image->stripImage();

    // re-apply the ICC profile
    if ($icc = $profiles['icc'] ?? null) {
        $image->profileImage('icc', $icc);
    }

    // save the image
    file_put_contents('./output-wrong.' . $ext, $image);
    // destroy the image
    $image->destroy();


    // re-open the output image and apply the ICC profile without calling stripImage
    $image = new Imagick('./output-wrong.' . $ext);
    if ($icc = $profiles['icc'] ?? null) {
        $image->profileImage('icc', $icc);
    }

    // save the image
    file_put_contents('./output-correct.' . $ext, $image);
    // destroy the image
    $image->destroy();
}

doTest('./png-adobe-rgb-gps.png', 'png');
doTest('./onigiri-adobe-rgb-gps.jpg', 'jpg');

Execute this in a folder with the png-adobe-rgb-gps.png and onigiri-adobe-rgb-gps.jpg images. You should end up with two sets of output-wrong.* a output-correct.* files. The "output-wrong" files do what you're doing in Kirby, the "output-correct" files are made by opening the "output-wrong" files and only re-adding the ICC profile.

The ICC profiles being present in:

  output-wrong output-correct
png
jpg

I know the top comment in the PHP guide about stripImage() suggests doing exactly this, but it doesn't seem to work, at least for not for PNG files.

Imho this looks like a bug in either Imagick or ImageMagick, because other file formats seem to work ootb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: help 🙏 Really needs some help on this
Development

Successfully merging this pull request may close these issues.

ImageMagick compatibilty issue on Ubuntu latest as 24
4 participants