Creating black images when trying to create thumbnails

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • amsablotny@yahoo.com

    #1

    Creating black images when trying to create thumbnails

    Hi all,

    I am a newbie at this. I am trying to create thumbnails. However, I
    am only creating black image with the correct thumbnail size. I am
    using php 5.1.6 and GD 2.0.28. Below is the code that I am using.
    Can any one help?

    Thanks,

    Alanna

    =============== =============== ===

    function createThumbnail ($imageDirector y, $imageName, $thumbDirectory ,
    $thumbWidth)
    {
    $srcImg = imagecreatefrom jpeg("$imageDir ectory/$imageName");
    $origWidth = imagesx($srcImg );
    $origHeight = imagesy($srcImg );

    $thumbHeight =200;
    $thumbWidth =100;

    if($origWidth $origHeight && $thumbHeight < $origHeight){
    $thumbHeight = $origHeight / ($origWidth / $thumbWidth);
    } else if ($origWidth < $origHeight && $thumbWidth < $origWidth)
    {
    $thumbWidth = $origWidth / ($origHeight / $thumbHeight);
    } else {
    $thumbWidth = $origWidth;
    $thumbHeight = $origHeight;
    }
    $thumbImg = imagecreatetrue color($thumbWid th, $thumbHeight);

    imagecopyresamp led($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth,
    $thumbHeight, origWidth, $origHeight);

    imagejpeg($thum bImg, "$thumbDirector y/$imageName");
    }

    if(!file_exists ("/home/alanna/public_html/pics/thumb/")){
    if(!mkdir("/home/alanna/public_html/pics/thumb/")) {
    echo "error making thumbs directory";
    }
    }

    if(file_exists( "/home/alanna/public_html/pics/thumb/". $imagename)){
    echo "File already exists";
    }
    else
    {

    createThumbnail ("/home/alanna/public_html/pics/full/", $imagename, "/
    home/alanna/public_html/pics/thumb/", 100);

    }

  • Erwin Moller

    #2
    Re: Creating black images when trying to create thumbnails

    amsablotny@yaho o.com wrote:
    Hi all,
    >
    I am a newbie at this. I am trying to create thumbnails. However, I
    am only creating black image with the correct thumbnail size. I am
    using php 5.1.6 and GD 2.0.28. Below is the code that I am using.
    Can any one help?
    >
    Thanks,
    >
    Alanna
    >
    =============== =============== ===
    >
    function createThumbnail ($imageDirector y, $imageName, $thumbDirectory ,
    $thumbWidth)
    {
    $srcImg = imagecreatefrom jpeg("$imageDir ectory/$imageName");
    $origWidth = imagesx($srcImg );
    $origHeight = imagesy($srcImg );
    >
    $thumbHeight =200;
    $thumbWidth =100;
    >
    if($origWidth $origHeight && $thumbHeight < $origHeight){
    $thumbHeight = $origHeight / ($origWidth / $thumbWidth);
    } else if ($origWidth < $origHeight && $thumbWidth < $origWidth)
    {
    $thumbWidth = $origWidth / ($origHeight / $thumbHeight);
    } else {
    $thumbWidth = $origWidth;
    $thumbHeight = $origHeight;
    }
    $thumbImg = imagecreatetrue color($thumbWid th, $thumbHeight);
    >
    imagecopyresamp led($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth,
    $thumbHeight, origWidth, $origHeight);
    >
    imagejpeg($thum bImg, "$thumbDirector y/$imageName");
    }
    >
    if(!file_exists ("/home/alanna/public_html/pics/thumb/")){
    if(!mkdir("/home/alanna/public_html/pics/thumb/")) {
    echo "error making thumbs directory";
    }
    }
    >
    if(file_exists( "/home/alanna/public_html/pics/thumb/". $imagename)){
    echo "File already exists";
    }
    else
    {
    >
    createThumbnail ("/home/alanna/public_html/pics/full/", $imagename, "/
    home/alanna/public_html/pics/thumb/", 100);
    >
    }
    Hi,

    To debug imagecreationsc ripts try the following:
    1) Set the header for mimetype from image/jpeg (or whatever it is) to
    text/html
    2) Run your script.

    That way your browser can actually display any errors in your script.
    If you leave the mimetype to an image, the browser will try to interpret
    your echos as an image, maybe resulting in a black image.

    Of course, when you fixed your errors, you can switch back to image/jpeg to
    check if PHP actually delivers an image you like.


    Regards,
    Erwin Moller
    Regards,
    Erwin Moller

    Comment

    Working...