Skip to content

Wrong colors used in output.jpg #435

Open

Description

@OskarStark

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

Activity

  1. OskarStark commented on May 19, 2015

    @OskarStark
    Author

    anybody?

  2. mvhirsch commented on May 19, 2015

    @mvhirsch

    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!

  3. coalexe commented on Jan 4, 2016

    @coalexe

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

  4. Marc-pi commented on Mar 6, 2016

    @Marc-pi

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

  5. azhidkov commented on Aug 8, 2016

    @azhidkov

    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.

  6. KacerCZ commented on Aug 30, 2018

    @KacerCZ

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions