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 08-15-2006, 04:58 PM   PM User | #1
Jak-S
Regular Coder

 
Join Date: Mar 2005
Location: Brighton, UK
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
Jak-S is an unknown quantity at this point
GD imagecopy problems with black background

This function is part of a class, it basically creates a new image in the dimensions specified, and then copies in the image held in $this->image. The image that is copied in will never be bigger than the new image (that is taken care of in another function) but one or both of the dimensions could be less than the new image (if the ratio isn’t the same).

It all works perfectly, it creates a new true colour image, fills it in white, but then when it runs the imagecopy function it seems to forget the fact that I set the background to white, and the image that results has a black border.

For example if I wanted a 100x100 image, and I was copying a 100x50 image in, I would end up with a 100x100 image with the old image centred vertically and a 25px black stripe above and below, I want those stripes to be white.

Any ideas?

PHP Code:
function crop($width null$height null)
{                    
    
// get the current widths and heights
    
$current_width    imagesx($this->image);
    
$current_height    imagesy($this->image);
    
    
$crop_top floor(($current_width $width) / 2);
    
$crop_left floor(($current_height $height) / 2);
                            
    
// create a new image resource
    
$temp    imagecreatetruecolor($width$height);
    
$white    imagecolorallocate($temp255255255);
    
imagefill($temp00$white);

    
// copy image into new resource
    
imagecopy($temp$this->image00$crop_top$crop_left$width$height);

    
// destroy original image
    
imagedestroy($this->image);
    
    
// copy new image
    
$this->image $temp;

Thanks in advance,
Jack

P.S. This function probably shouldnt actually be called crop, as thats not what it does, incase that confused anyone.

Last edited by Jak-S; 08-15-2006 at 05:04 PM..
Jak-S is offline   Reply With Quote
Old 08-15-2006, 07:04 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Is the image you are copying into $temp a true color image? If it is paletted (gif for example), you'll probably need to do imagecreate() instead of imagecreatetruecolor(). (That's my guess)
Fumigator is offline   Reply With Quote
Old 08-16-2006, 10:28 AM   PM User | #3
Jak-S
Regular Coder

 
Join Date: Mar 2005
Location: Brighton, UK
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
Jak-S is an unknown quantity at this point
Yeah it is a true colour image, a JPEG.
Jak-S is offline   Reply With Quote
Old 01-25-2007, 10:06 PM   PM User | #4
uji
New to the CF scene

 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
uji is an unknown quantity at this point
black thumbnails in gd . . .

on a related note I'm having problems with gd thumbnail rendering and can't seem to find a solution anywhere.
have you heard of this issue or are you having any luck finding out why gd is generating a black background?
the issues may be related . . .

thanks...
uji 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 06:19 AM.


Advertisement
Log in to turn off these ads.