Note that there are some explanatory texts on larger screens.

plurals
  1. POTransforming transparent `gif` to grayscale while saving transparency
    text
    copied!<p>First, I resize the image while saving transparency:</p> <pre><code>/* all the classic routine etcetera: $canvas = imagecreatefrom[png|gif|jpeg](); $resize = imagecreatetruecolor(); */ if($blending){ $transparentIndex = imagecolortransparent($canvas); if($transparentIndex &gt;= 0){ #GIF imagepalettecopy($canvas, $resize); imagefill($resize, 0, 0, $transparentIndex); imagecolortransparent($resize, $transparentIndex); imagetruecolortopalette($resize, true, 256); }else{ #PNG imagealphablending($resize, false); imagesavealpha($resize, true); $transparent = imagecolorallocatealpha($resize, 255, 255, 255, 127); imagefill($resize, 0, 0, $transparent); } } imagecopyresampled($resize, $canvas, 0, 0, 0, 0, $nx, $ny, $x, $y); // image[png|gif|jpeg]... (image gets saved) </code></pre> <p>Then, I want to apply grayscale filter to that previously saved image (within a new function):</p> <pre><code>/* classic routine again: $canvas = imagecreatefrom[png|gif|jpeg]() */ if($blending){ imagealphablending($canvas, false); imagesavealpha($canvas, true); } imagefilter($canvas, IMG_FILTER_GRAYSCALE); /* This fully filters PNG's to Grayscale while saving transparency, but for GIF, black background is added to my grayscaled picture, plus, the picture isn't fully grayscale (more like gets high-contrasted with acidic colors). */ // image[png|gif|jpeg] </code></pre> <p><s>What would be the fix, to preserve transparency when applying IMG_FILTER_GRAYSCALE to <code>gif</code>?</s></p> <p>What would be the fix, in order to transform <code>gif</code> to grayscale while saving the transparency? (Question revised due to answer provided by @Pierre)</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload