Jump to content

[SOLVED] Little problem with image thumbnail function


evanct

Recommended Posts

function createThumbnail($path,$tn_src) {
require('config.php');
    $size = getimagesize($path);
    $width = $size[0];
    $height = $size[1];

    if($width> $height) {
        $x = ceil(($width - $height) / 2 );
        $width = $height;
    } elseif($height> $width) {
        $y = ceil(($height - $width) / 2);
        $height = $width;
    }

    $new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
    $im = imagecreatefromjpeg($path);
    imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
    imagejpeg($new_im,$tn_src,100);
}

 

this works perfectly, it creates a 100x100 thumbnail of the image and puts it in the directory. the Little Problem is that the thumbnail it creates is a 100% black image. what's wrong here?

I set error_reporting to display warnings, and I get this: "Warning: imagecopyresampled(): supplied argument is not a valid Image resource". I split up the parameters of imagecopyresampled() so each was on its own line, and it pointed to $height.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.