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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 29 2025 14:41:57
Script start
Timing: Jan 29 2025 14:41:57
Module start 'layout'
Timing: Jan 29 2025 14:41:57
Module start 'content'
Timing: Jan 29 2025 14:41:57
Module end 'content'
Timing: Jan 29 2025 14:41:57
Script end

Main resources:

Total runtime0.0163 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 588.2656151.2266
Module start 'layout' 0.00580.0030 739.492236.6797
Module start 'content' 0.00880.0060 776.171994.4063
Module end 'content' 0.01490.0014 870.578137.9922
Script end 0.0162  908.5703 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002213.5107140.0002
Check MTime0.00106.3167140.0001
Mysql Total
Database connection0.00063.482810.0006
Mysqli_queries0.003722.906030.0012
Looping result0.00000.086410.0000
Template Total0.00116.610.0011
Template load0.00085.129010.0008
Template processing0.00021.461610.0002
Override
Cache load0.00063.476910.0006
General
dbfile0.002213.263280.0003
String conversion0.00000.055740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs