Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-06-2007, 11:59 PM   PM User | #1
Big-Pat
New Coder

 
Join Date: May 2006
Posts: 34
Thanks: 2
Thanked 1 Time in 1 Post
Big-Pat is an unknown quantity at this point
GD Image Problems - Transparent Background

I'm trying to create a PHP script to take a large image (2.1 Mb) and cut it in half and resize it. I don't really know what I'm doing, this is the first time I've used these functions. The problem I'm having is that is has a drop shadow and in the process of keeping the background transparent it gets removed badly and I end up with this:



My code (from tutorials and php manual):
PHP Code:
<?php
$width 
58;
$height 142;
$canvas imagecreatetruecolor($width,$height);
$piece imagecreatefrompng('orn-ball.png');
$transp imagecolorallocate($piece,0,0,0);
imagecolortransparent($canvas,$transp);
$newwidth 500;
$newheight 1000;
$cropLeft 7;
$cropHeight 7;
imagecopyresized($canvas$piece0,0$cropLeft$cropHeight$width$height$newwidth$newheight);
if (
imagepng($canvas,'test.png',90)) {
echo 
'Image crop successful';
} else {
echo 
'Image crop failed';
}
imagedestroy($canvas);
imagedestroy($piece);
?>
Big-Pat is offline   Reply With Quote
Old 01-09-2007, 03:22 AM   PM User | #2
Big-Pat
New Coder

 
Join Date: May 2006
Posts: 34
Thanks: 2
Thanked 1 Time in 1 Post
Big-Pat is an unknown quantity at this point
bumper
Big-Pat is offline   Reply With Quote
Old 01-09-2007, 03:45 AM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,738
Thanks: 4
Thanked 2,464 Times in 2,433 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Looks fine to me (in FF).
Hint, IE doesn't know how to handle the alpha layer for the png images. Unfortunatly, the gif is your next best bet, but I'm not sure how the colour allocation will look with the 256 colours available.
Does that answer your question?
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Old 01-09-2007, 04:16 AM   PM User | #4
Big-Pat
New Coder

 
Join Date: May 2006
Posts: 34
Thanks: 2
Thanked 1 Time in 1 Post
Big-Pat is an unknown quantity at this point
I am using FF 2.0, but I don't know if this is a limitation of the resizing, but the edges aren't smooth and the drop shadow is removed. I understand that this is because of imagecreatetruecolor() creates a black base image, is there any way to get around this? or is it something else.
Big-Pat is offline   Reply With Quote
Old 01-10-2007, 02:59 AM   PM User | #5
Big-Pat
New Coder

 
Join Date: May 2006
Posts: 34
Thanks: 2
Thanked 1 Time in 1 Post
Big-Pat is an unknown quantity at this point
B-Bump
Big-Pat is offline   Reply With Quote
Old 02-23-2007, 12:11 AM   PM User | #6
Gater
New to the CF scene

 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Gater is an unknown quantity at this point
Similar problem, with possible solution

Here is a snapshot of the critical code...

PHP Code:
// Create the destination image
$oDestinationImage imagecreatetruecolor($width$height);

// Create the palette
$nrcolors imagecolorstotal($oSourceImage); 
imagetruecolortopalette($oDestinationImagetrue$nrcolors);

// Create and set the transparent background color
$color imagecolortransparent($oSourceImage);
$color imagecolorallocate($oDestinationImage,
0xFF & ($color >> 0x10),
0xFF & ($color >> 0x8),
0xFF $color);
$color imagecolortransparent($oDestinationImage$color);

// Fill the destination image with the transparent color
imagefill($oDestinationImage0,0$color); 
Gater is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:38 AM.


Advertisement
Log in to turn off these ads.