Forums / Developer / PNG loses transparency when merging with image()

PNG loses transparency when merging with image()

Author Message

Marko Žmak

Thursday 25 March 2010 11:55:31 am

I have two transparent PNGs and I want to merge them into one transparent PNG using the image() operator. But it doesn't work, the resulting image looses transparency and is converted to black and white. This is the code I use:

{image(

 imagefile( 'design/dev/images/image1.png'),

 array(

  imagefile( 'design/dev/images/image2.png' ) ,

  hash(

    halign, left,

    valign, top

  ) 

 )

)}

Am I doing something wrong, or the problem is in eZ?

This could be related to this forum post:

http://share.ez.no/forums/developer/png-image-resize-loose-transparency

and this issue:

http://issues.ez.no/IssueView.php?Id=15640

Can someone confirm this is a bug in eZ?

P.S. I'm using eZ 4.1.4

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Robin Muilwijk

Thursday 25 March 2010 1:47:56 pm

Hi,

I just read http://stackoverflow.com/questions/32243/can-png-image-transparency-be-preserved-when-using-phps-gdlib-imagecopyresampled, where they use the following code:

<span class="pln">imagealphablending</span><span class="pun">(</span><span class="pln"> $targetImage</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">false</span><span class="pln"> </span><span class="pun">);</span><span class="pln">
imagesavealpha</span><span class="pun">(</span><span class="pln"> $targetImage</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">true</span><span class="pln"> </span><span class="pun">);</span><span class="pln">
</span>

This requires GD2 though, if you look at /settings/image.ini you can enable GD2. I'm no coder but maybe this helps you to find a solution.

Regards Robin

Board member, eZ Publish Community Project Board - Member of the share.ez.no team - Key values: Openness and Innovation.

LinkedIn: http://nl.linkedin.com/in/robinmuilwijk // Twitter: http://twitter.com/i_robin // Skype: robin.muilwijk

Vytautas Germanavičius

Friday 17 June 2011 8:23:33 am

This message gave me idea
 http://stackoverflow.com/questions/32243/can-png-image-transparency-be-preserved-when-using-phps-gdlib-imagecopyresampled

And i made small changes in ezimagegdhandler.php:
 i added

    imagealphablending( $temporaryImageObject, false );    imagesavealpha( $temporaryImageObject, true );

 after

       $temporaryImageObject = eZImageGDHandler::imageCreate( $destinationWidth, $destinationHeight, eZImageGDHandler::isImageTrueColor( $imageObject, $sourceMimeData ) );

It saves PNG transparency before resizing.

I made patch, if someone is interested. http://issues.ez.no/IssueView.php?Id=15640&activeItem=1

{set-block scope=root variable=cache_ttl}0{/set-block}

Marko Žmak

Friday 17 June 2011 9:27:40 am

And how about creating a pull request on eZP github?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth