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 6 of 6
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post

    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);
    ?>

  • #2
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post
    bumper

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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'); 

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #5
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post
    B-Bump

  • #6
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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); 


  •  

    Posting Permissions

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