Page 1 of 1

GD not a valid image resource

Posted: Sat Jun 25, 2005 9:44 am
by robjime
when i try a simple gd function,

Code: Select all

$uploadFileDir = $uploadDir . $origname;
$sizex = imagesx($uploadFileDir);
I tried it where c:/images/image.jpg was my image.

The script returned:

Code: Select all

Warning: imagesx(): supplied argument is not a valid Image resource in
whats the problem?

Posted: Sat Jun 25, 2005 10:19 am
by dethron
;)

Code: Select all

<?
#$imagem - source of image
#$dpi - resolution to convert E.g.: 72dpi or 300dpi

function px2cm($image, $dpi) {
   #Create a new image from file or URL
   $img = ImageCreateFromJpeg($image);

   #Get image width / height
   $x = ImageSX($img);
   $y = ImageSY($img);
   
   #Convert to centimeter
   $h = $x * 2.54 / $dpi;
   $l = $y * 2.54 / $dpi;
   
   #Format a number with grouped thousands
   $h = number_format($h, 2, ',', ' ');
   $l = number_format($l, 2, ',', ' ');
   
   #add size unit
   $px2cm[] = $h."cm";
   $px2cm[] = $l."cm";
   
   #return array w values
   #$px2cm[0] = X
   #$px2cm[1] = Y    
   return $px2cm;
}

$image = "C:\\images\\image.jpg ";
$dpi = 300;

$result = px2cm($image, $dpi);

print ($result[0]." x ".$result[1]);
?>

Posted: Sat Jun 25, 2005 10:26 am
by dethron
As you can see, to create an image to pass ImageSX(), you need first ImageCreateFromJpeg() to create this image from your local file.