Advanced Search

Results 1 to 1 of 1

Thread: PHP GD Transparent Image issue

  1. #1
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP GD Transparent Image issue

    Hi People

    I'm having a really frustrating time with this script which I've cobbled together to produce a dynamic image of two polaroids. I have managed to resize, rotate and position the two images and overlay the polaroid frames over the top but I cannot get the images to display with a transparent background. If I add the usual imagealphablending($image, false); and imagesavealpha($image, true); lines of code, the image is transparent but the two rotated images disappear too! I'm not sure where I need to specify the transparent background in order to make it work! Can anyone help? Here is the code and an outputted image.




    PHP Code:
    <?php

      header 
    ('Content-Type: image/png');

    $file 'images/baselayer.png';
    list(
    $imagewidth$imageheight) = getimagesize($file);
    $image imagecreatefrompng($file);
    $setwidth 225;
    $setheight 230;
     
    $filename $_REQUEST['image1'];
    list(
    $width$height) = getimagesize($filename);
    if (
    $width == $height) { $height $height 1; }
    if (
    $width $height && $setwidth $setheight) { $case "1"; }
    if (
    $width $height && $setwidth $setheight) { $case "2"; }
    if (
    $width $height && $setwidth $setheight) { $case "3"; }
    if (
    $width $height && $setwidth $setheight) { $case "4"; }
    if (
    $width == $setwidth && $height == $setheight) { $case == "5"; }
     
    switch (
    $case) {
    case 
    "1" $rqst_pro $setheight $setwidth$orig_pro $height $width; if ($orig_pro $rqst_pro) { $dst_w $setwidth$dst_h round(($dst_w $width) * $height); $dst_y = (($setheight $dst_h) / 2); } else { $dst_h $setheight$dst_w round(($dst_h $height) * $width); $dst_y = (($setheight $dst_h) / 2); }
    break;
    case 
    "2" $rqst_pro $setwidth $setheight$orig_pro $width $height; if ($orig_pro $rqst_pro) { $dst_w $setwidth$dst_h round(($dst_w $width) * $height); $dst_x = (($setwidth $dst_w) / 2); } else { $dst_h $setheight$dst_w round(($dst_h $height) * $width); $dst_x = (($setwidth $dst_w) / 2); }
    break;
    case 
    "3" $dst_w $setwidth$dst_h round(($dst_w $width) * $height); $dst_y = (($setheight $dst_h) / 2);
    break;
    case 
    "4" $dst_h $setheight$dst_w round(($dst_h $height) * $width); $dst_x = (($setwidth $dst_w) / 2);
    break;
    case 
    "5" $dst_h $setheight$dst_w $setwidth;
    break;
    }

    $filename2 $_REQUEST['image2'];
    list(
    $width2$height2) = getimagesize($filename2);
    if (
    $width2 == $height2) { $height2 $height2 1; }
    if (
    $width2 $height2 && $setwidth $setheight) { $case2 "1"; }
    if (
    $width2 $height2 && $setwidth $setheight) { $case2 "2"; }
    if (
    $width2 $height2 && $setwidth $setheight) { $case2 "3"; }
    if (
    $width2 $height2 && $setwidth $setheight) { $case2 "4"; }
    if (
    $width2 == $setwidth && $height == $setheight) { $case2 == "5"; }
     
    switch (
    $case2) {
    case 
    "1" $rqst_pro2 $setheight $setwidth$orig_pro2 $height2 $width2; if ($orig_pro2 $rqst_pro2) { $dst_w2 $setwidth$dst_h2 round(($dst_w2 $width2) * $height2); $dst_y2 = (($setheight $dst_h2) / 2); } else { $dst_h2 $setheight$dst_w2 round(($dst_h2 $height2) * $width2); $dst_y2 = (($setheight $dst_h2) / 2); }
    break;
    case 
    "2" $rqst_pro2 $setwidth $setheight$orig_pro2 $width2 $height2; if ($orig_pro2 $rqst_pro2) { $dst_w2 $setwidth$dst_h2 round(($dst_w2 $width2) * $height2); $dst_x2 = (($setwidth $dst_w2) / 2); } else { $dst_h2 $setheight$dst_w2 round(($dst_h2 $height2) * $width2); $dst_x2 = (($setwidth $dst_w2) / 2); }
    break;
    case 
    "3" $dst_w2 $setwidth$dst_h2 round(($dst_w2 $width2) * $height2); $dst_y2 = (($setheight $dst_h2) / 2);
    break;
    case 
    "4" $dst_h2 $setheight$dst_w2 round(($dst_h2 $height2) * $width2); $dst_x2 = (($setwidth $dst_w2) / 2);
    break;
    case 
    "5" $dst_h2 $setheight$dst_w2 $setwidth;
    break;
    }

    $dst_image imagecreatetruecolor($setwidth$setheight);
    $src_image imagecreatefromjpeg($filename);
    imagecopyresampled ($dst_image$src_image$dst_x$dst_y00$dst_w$dst_h$width$height );
    $degrees 7;
    $rotate imagerotate($dst_image$degrees, -1);

    $dst_image2 imagecreatetruecolor($setwidth$setheight);
    $src_image2 imagecreatefromjpeg($filename2);
    imagecopyresampled ($dst_image2$src_image2$dst_x2$dst_y200$dst_w2$dst_h2$width2$height2 );
    $degrees2 = -7;
    $rotate2 imagerotate($dst_image2$degrees2, -1);
     
    imagecopy($image$rotate402500240220);
    imagecopy($image$rotate22804000240220);

    // define the sharpen matrix
    $sharpen = array(
        array(
    0.0, -1.00.0),
        array(-
    1.05.0, -1.0),
        array(
    0.0, -1.00.0)
    );

    // calculate the sharpen divisor
    $divisor array_sum(array_map('array_sum'$sharpen));

    // apply the matrix
    imageconvolution($image$sharpen$divisor0);

    $watermark imagecreatefrompng("images/toplayer.png");
    $watermark_width imagesx($watermark);
    $watermark_height imagesy($watermark);

    imagecopy($image$watermark0000$watermark_width$watermark_height);
     
    header('Content-type: image/png');
    imagepng($image);
    imagedestroy($image);
    Last edited by jscheuer1; 05-12-2011 at 05:29 AM. Reason: format code

Bookmarks

Posting Permissions

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