Part of the EllisLab Network
   
2 of 2
2
Image lib PNG transparency doesn’t work
Posted: 11 May 2008 10:02 PM   [ Ignore ]   [ # 16 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15294
Joined  06-03-2002

The main problem you encounter here is that all of the available methods to allow alpha transparent overlays drop support for setting the opacity, which means that opacity level can only be supported by creating the watermark file with the desired opacity from the start, which in turn requires that your source image have alpha transparency.  I’m no more comfortable with making the watermark only work correctly with PNG-24 than I am with its current limitation, so some deeper solution will be required.

 Signature 
Profile
MSG
 
 
Posted: 11 May 2008 10:20 PM   [ Ignore ]   [ # 17 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15294
Joined  06-03-2002

Well, late night at the end of the weekend, and I am in a talking to myself mood.  Plus I don’t want to forget this when I wake up and actually start work tomorrow.  I suppose there is always the option of doing both, depending on whether we can make a good guess as to whether or not the watermark image has alpha transparency.  Still not perfect, though, like the current lib method, as if you have solid pixels at (4, 4) it won’t get it right.

// Set RGB values for text and shadow
$rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp);
$alpha = ($rgba & 0x7F000000) >> 24;

// if there's an alpha value > 0, we know we have a PNG-24
if ($alpha > 0)
{
    imagecopy
($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height);
}
else
{
    imagecolortransparent
($wm_img, $rgba);
    
imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity);            
}

 Signature 
Profile
MSG
 
 
Posted: 12 May 2008 09:51 AM   [ Ignore ]   [ # 18 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15294
Joined  06-03-2002

After a good night’s rest and two cups of coffee, I’ve decided that since this is an improvement and doesn’t change functionality, it’s going in.

 Signature 
Profile
MSG
 
 
Posted: 12 May 2008 09:54 AM   [ Ignore ]   [ # 19 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  666
Joined  04-20-2006

Hi Derek,

I hope the coffee was good grin

I am not sure I have understood what you mean above, is your “patch” became part of CI now or did you decide to leave it?

 Signature 

All CodeIgniter resources in 1 place?
http://www.codeigniterdirectory.com (Did you know we are converting this directory to Linkster? We need a Graphic designer, join us!)

My website: Création de sites Genève, Too Pixel

Profile
 
 
Posted: 12 May 2008 10:01 AM   [ Ignore ]   [ # 20 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15294
Joined  06-03-2002

It’s in the svn, ready for 1.6.2.

 Signature 
Profile
MSG
 
 
Posted: 12 May 2008 10:05 AM   [ Ignore ]   [ # 21 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  666
Joined  04-20-2006

Cool !

 Signature 

All CodeIgniter resources in 1 place?
http://www.codeigniterdirectory.com (Did you know we are converting this directory to Linkster? We need a Graphic designer, join us!)

My website: Création de sites Genève, Too Pixel

Profile
 
 
Posted: 15 May 2008 06:34 PM   [ Ignore ]   [ # 22 ]  
Lab Assistant
RankRank
Total Posts:  131
Joined  01-02-2008

Is this confirmed fixed for resizing, croping and rotating as well?
-Matt

Profile
 
 
Posted: 15 May 2008 10:53 PM   [ Ignore ]   [ # 23 ]  
Grad Student
Rank
Total Posts:  33
Joined  03-11-2008

It doesn’t work for resizing yet. Transparent 8-bit PNG images fail, as well as grayscale PNG’s.

Check the attachment to see how broken images look.

Sample images are from http://puna.net.nz/archives/Design/PNG transparency test_files/
Left image is the original, right is the thumbnail. The last row shows how they should all look like.

Image Attachments
Picture 2.png
Click thumbnail to see full-size image
Profile
 
 
Posted: 15 May 2008 11:45 PM   [ Ignore ]   [ # 24 ]  
Grad Student
Rank
Total Posts:  33
Joined  03-11-2008

Grayscale + alpha PNG’s are actually a GD bug as documented here.
The bug was fixed in GD 2.0.36, and GD 2.1.0.

Profile
 
 
   
2 of 2
2
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 62663 Total Logged-in Users: 35
Total Topics: 77201 Total Anonymous Users: 1
Total Replies: 416758 Total Guests: 266
Total Posts: 493959    
Members ( View Memberlist )