Loading...
 
Skip to main content

Features / Usability


Resized Images: Background from transparent to black (or white)

I'm using Tiki 6.2 at present.

I've uploaded a graphic with a transparent background. I can call it using the {IMG} Plugin with no problems — that is, it displays with its transparent background, and if I right-click on it, Save as...and pull it into Photoshop Elements, I can see that it has retained its transparent background.

The problem is when I use "height" or "width" to make the graphics smaller (haven't tried bigger yet). When I do that, the graphic is displayed at the requested size with a black background — or almost black — when I right-click/SaveAs.../pull it into Photoshop Elements, the background is #020402.

Since I'm using GD, I tried making a change to gd.php in the "function_resize" section:

Copy to clipboard
$t = imagecreatetruecolor($x, $y); imagecopyresampled($t, $this->data, 0, 0, 0, 0, $x, $y, $this->get_width(), $this->get_height());

Copy to clipboard
$t = imagecreatetruecolor($x, $y); imagealphablending($t, false); imagesavealpha($t,true); $transparent = imagecolorallocatealpha($t, 255, 255, 255, 127); imagefilledrectangle($t, 0, 0, $x, $y, $transparent); imagecopyresized($t, $this->data, 0, 0, 0, 0, $x, $y,$this->get_width(), $this->get_height());


Now the behavior's weirder. The graphic still displays in its page with a black background. If I right-click on it and open it up in a new tab, it shows up with an almost white background (#fcfefc).

The file gd.php calls to abstract.php, but I can't see anything obvious that has anything to do with background colors. But I freely admit that I don't know much about PHP at all.

BTW, I used the above code in tiki-pick_avatar.php to fix the problem I was having with all avatars being resized to JPEGs with a black background. I can now upload PNGs or GIFs with transparent backgrounds and have them retain their file types and transparency (the imagecopyresized doesn't do as nice of a job as imagecopyresampled, but these are smallish graphics to start with anyway so it doesn't really matter). I've confirmed, by pulling them down and opening them in Elements, that the resized graphics have transparent backgrounds.

I can see that gd.php operates differently, in that it doesn't write the image to file the way tiki-pick_avatar.php does. I don't know if that's the difference.

Any help you can point me towards explaining exactly where in the process of {IMG} handling tiki is actually modifying the original graphic would be greatly appreciated. Thanks in advance!