Author Topic: upload and resize png/gif with transparency --> patch  (Read 2215 times)

mike5464

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
upload and resize png/gif with transparency --> patch
« on: June 06, 2009, 06:39:18 pm »
hello

I tried to add a logo in the society panel but i only got a full black image. I understood that the problem was coming from the transparency of the png logo.

I checked the SimpleGdImage.class.php and saw that there was no support for transparency in the scale function. After some research and test here is the patch.

The file is locate into opengoo/library/simplegd/classes
The original version : Line 341 to 347
Code: [Select]
if($this->getImageType() == IMAGETYPE_GIF) {
        $new_resource = imagecreate($new_width, $new_height);
      } else {
        $new_resource = imagecreatetruecolor($new_width, $new_height);
      } // if
     
      imagecopyresampled($new_resource, $this->resource, 0, 0, 0, 0, $new_width, $new_height, $this->getWidth(), $this->getHeight());

And now it became

Code: [Select]
if($this->getImageType() == IMAGETYPE_GIF) {
        $new_resource = imagecreate($new_width, $new_height);
        $originaltransparentcolor = imagecolortransparent( $this->resource );
if(
    $originaltransparentcolor >= 0 // -1 for opaque image
    && $originaltransparentcolor < imagecolorstotal( $this->resource )
    // for animated GIF, imagecolortransparent will return a color index larger
    // than total colors, in this case the image is treated as opaque ( actually
    // it is opaque )
) {
    $transparentcolor = imagecolorsforindex( $this->resource, $originaltransparentcolor );
    $newtransparentcolor = imagecolorallocate($new_resource,$transparentcolor['red'],$transparentcolor['green'],
$transparentcolor['blue']);
// for true color image, we must fill the background manually
imagefill( $new_resource, 0, 0, $newtransparentcolor );
// assign the transparent color in the thumbnail image
imagecolortransparent( $new_resource, $newtransparentcolor );
}
      } else {
        $new_resource = imagecreatetruecolor($new_width, $new_height);
        imagealphablending($new_resource, false);
        imagesavealpha($new_resource, true);
      } // if
     
      imagecopyresampled($new_resource, $this->resource, 0, 0, 0, 0, $new_width, $new_height, $this->getWidth(), $this->getHeight());

The part for the gestion of the transparency for gif came from http://be.php.net/manual/fr/function.imagecopyresized.php#76648 and seems to work with animated gif but i didn't tried.

This version has been tested with jpg, png with transparency, png without, gif with transparency and without.

Thanks for a so cool program.

I don't know were to put it so i link here my version of SimpleGdImage.class.php

alvarotm01

  • Administrator
  • Sr. Member
  • *****
  • Posts: 335
    • View Profile
    • Email
Re: upload and resize png/gif with transparency --> patch
« Reply #1 on: June 08, 2009, 10:30:12 am »
Hi Mike,

Thank you very much for the patch !!!
We are very happy to receive this type of contributions !

We will add it to the next release.

cheers

mike5464

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: upload and resize png/gif with transparency --> patch
« Reply #2 on: June 08, 2009, 11:09:00 am »
I don't know if there is a proper way for posting patch like a cvs repository or something like that.
If there is i would be pleased to post future patch on it.

Edit :

I am a bit slow some times but i am in exam so...
I "founded" the repository on sourceforge and the bug tracker and everthing but i seems like if it was not longer used. What are we suppose to use, this forum or the bugtracker on sourceforge or something else ?
« Last Edit: June 08, 2009, 11:16:35 am by mike5464 »

alvarotm01

  • Administrator
  • Sr. Member
  • *****
  • Posts: 335
    • View Profile
    • Email
Re: upload and resize png/gif with transparency --> patch
« Reply #3 on: June 08, 2009, 01:51:22 pm »
No, at this moment we haven't any repository for patches, you can post them here or send to us via mail.
We are not using anymore the bugtracker in sourceforge, the bugs are being reported here at the forum, in this board and its sub boards.

 

anything