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

Problem with composite and invalid icc #3348

Open
JohnnyTWA opened this issue Feb 17, 2023 · 1 comment
Open

Problem with composite and invalid icc #3348

JohnnyTWA opened this issue Feb 17, 2023 · 1 comment

Comments

@JohnnyTWA
Copy link

Hello,

I'm running the code below and getting an error (albeit only with this image...so far)

libvips error: composite: images do not have same numbers of bands

require_once("vendor/autoload.php");

use Jcupitt\Vips\Exception;
use Jcupitt\Vips\Image as VipsImage;
use Jcupitt\Vips\BlendMode;

$overlay_file = 'avatar.png';

$overlay = VipsImage::newFromFile($overlay_file);

$file = 'problem-image.jpg';

$image = VipsImage::newFromFile($file);

$x = 50;
$y = 50;

if (!$overlay->hasAlpha()) {
    $overlay = $overlay->bandjoin(255);
}

$watermark_alpha = $overlay[$overlay->bands - 1];
$overlay = $overlay->extract_band(0, ['n' => $watermark->bands - 1]);
$watermark_alpha = $watermark_alpha->multiply((50 / 100));
$overlay = $overlay->bandjoin($watermark_alpha);

$image = $image->composite($overlay, [BlendMode::OVER], ['x' => $x, 'y' => $y]);

$output = 'output.jpg';

$image->writeToFile($output, ['Q' => 70, 'strip' => true, 'optimize_coding' => true, 'background' => 255]);

From doing some investigation Photoshop tells me the problem image has an invalid ICC profile, and removing it before processing the image does mean the code completes successfully.

Is there a way of detecting whether the profile is compatible with the image, icc_import succeeds (The number of bands changes from 3 to 5).

problem-image
avatar

Thanks in advance.

@jcupitt
Copy link
Member

jcupitt commented Feb 17, 2023

Hi @JohnnyTWA,

I had a quick look -- your image has three bands, even though it's black and white. I guess someone saved as RGB at some point in the past. The profile on the image is still monochrome.

When icc_import runs it sees a three-band image plus a mono profile and decides you probably have a mono image with two alpha channels (ie. GAA). That gets turned into LAB, so LABAA, so five bands.

Maybe we could tune the rules it uses a little -- GAA has to be pretty unusual, so RGB might be a better guess. Let's leave this issue open as an enhancement.

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

No branches or pull requests

2 participants