Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Location
    Brighton, UK
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 06:04 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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)

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Location
    Brighton, UK
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah it is a true colour image, a JPEG.

  • #4
    uji
    uji is offline
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •