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

Wrong colors used in output.jpg #435

Open
OskarStark opened this issue May 18, 2015 · 6 comments
Open

Wrong colors used in output.jpg #435

OskarStark opened this issue May 18, 2015 · 6 comments

Comments

@OskarStark
Copy link

Hi Guys!
I'm using PHP 5.5 and tried Gmagick, Imagick and GD

Start with this image `ìnput.jpg`` (800x1200px) - color is CORRECT:
input

$imagine = new Imagine();

/* set height to 800px (current 1200px) */
$file = $imagine->open($inputFile);
$size = $file->getSize();
$targetSize = new Box($size->getWidth(), $size->getHeight());
$file->resize($targetSize->heighten(800))->save($tempOutputFile);

/* get the resized image 533x800px*/
$createdFile = $imagine->open($tempOutputFile);

Temp image temp_outpur.jpgis no 533x800px - color is STILL CORRECT:
temp_output

/* we need 667x800px so i want to apply white pixels to right and the left

/* drawing a new image with the needed pixels */
$newBox = new Box(667, 800);
$emptyImage = $imagine->create($newBox);

$size = $emptyImage->getSize();
$wSize = $createdFile->getSize();

/* calculate the center x-point */
$x = ($size->getWidth() / 2) - ($wSize->getWidth() / 2);
$center = new Point($x, 0);

/* paste the temp_output.jpg onto the created file */
$emptyImage->paste($createdFile, $center);
$emptyImage->save($outputFile);

The result output.jpg 667x800px - color is INCORRECT:
output

Here is a Side-by-Side diff (output.jpg is a little bit gray....):
bildschirmfoto 2015-05-18 um 12 26 27

@OskarStark
Copy link
Author

anybody?

@mvhirsch
Copy link

I tried with imagick and gd.
I also skipped the temporary save within this to lines to save image quality:

$file->resize($targetSize->heighten(800))->save($tempOutputFile);
$createdFile = $imagine->open($tempOutputFile);

But neither things worked for me. Please help!

@coalexe
Copy link

coalexe commented Jan 4, 2016

Got the same problem. Image is grayed out a little.

@Marc-pi
Copy link

Marc-pi commented Mar 6, 2016

we have also this behavior when image are downsized (landscape highres pictures)
@romainneutron any idea ? merci !

@azhidkov
Copy link

azhidkov commented Aug 8, 2016

I had the similar problem when after image resizing colors become a little bit "zombie". And I've used this code for resizing:

use Imagine\Imagick\Imagine;
use Imagine\Image\Box;

$imagine = new Imagine();

// $file contains path to the file
$image = $imagine->open($file)
    ->thumbnail(new Box(1500, 980))
    ->save($outputFileName, ['jpeg_quality' => 90]);

Solution for me was comment the line with image stripping:

...
$thumbnail->usePalette($this->palette());
//$thumbnail->strip(); <-- comment this line
...

in method \Imagine\Image\AbstractImage::thumbnail.

Image weight become more but the quality is good.

@KacerCZ
Copy link

KacerCZ commented Aug 30, 2018

I've encountered the same problem.
Cause of this problem is, that color profile is removed in strip().

This modification of \Imagine\Image\AbstractImage::thumbnail() copies color profile from original image to thumbnail:

...
$thumbnail->strip();
$thumbnail->profile($this->palette()->profile());
...

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

No branches or pull requests

6 participants