Domanda

I'm using php Gmagick to modify images. The following code works as expected except that the images are not progressive. Why? According to the GraphicsMagick docs it should. For reference, the input image is 666 x 1000.

    $img = new Gmagick();
    $img->setSize(900, 900)
        ->readImageBlob($image->getBytes())
        ->setImageInterlaceScheme(Gmagick::INTERLACE_PLANE)
        ->setImageResolution(96, 96)
        ->setImageFormat('jpeg')
        ->setCompressionQuality(70)
        ->resizeImage(900, 1351, Gmagick::FILTER_UNDEFINED, 1);

Note that

$img->getImageInterlaceScheme() === Gmagick::INTERLACE_PLANE

does return true after setting it.

Edit

I've tried both the INTERLACE_LINE and INTERLACE_PLANE constants. With neither seeming to have an effect on the output.

È stato utile?

Soluzione

The original author created a bug on php.net (https://bugs.php.net/bug.php?id=66444), where the correct answer was eventually posted. You need to use the undocumented method:

->setInterlaceScheme(Gmagick::INTERLACE_LINE)

Instead of:

->setImageInterlaceScheme(Gmagick::INTERLACE_LINE)

This worked for me! For reference I am using PHP 5.4.20 with gmagick 1.1.7RC2 on top of GraphicsMagick 1.3.18.

Altri suggerimenti

The documentation you point to states:

Use Line to create an interlaced PNG or GIF or progressive JPEG image.

So, I think you should be setting the interlace to line.

->setImageInterlaceScheme(Gmagick::INTERLACE_LINE)

Note: I'm not sure if INTERLACE_LINE is an actual value. I assumed it was based on your code. Basically, try the line option.

Have you tried calling setImageInterlaceScheme before anything else? i cannot find the code, but maybe when you read the bits it already compose the image and then the interlacings takes no place.

$img
    ->setImageInterlaceScheme(Gmagick::INTERLACE_PLANE)
    ->readImageBlob($image->getBytes())
    ->setSize(900, 900) 
    ->setImageResolution(96, 96)
    ->setImageFormat('jpeg')
    ->setCompressionQuality(70)
    ->resizeImage(900, 1351, Gmagick::FILTER_UNDEFINED, 1);

For sure the interlaceScheme has to be INTERLACE_PLANE, as you can read in the docs you already know http://www.graphicsmagick.org/GraphicsMagick.html#details-interlace

I've finally found the answer to this (using PHP IMagick) after struggling for weeks.

It turns out you have to set the image format to 'pjpeg' instead of just jpeg.

I have no idea why by by doing so my Images are correctly detect as progressive and render progressively in the browser.

I assume this will be the same for 'GMagick'

$im->setImageFormat('pjpeg')
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top