Hi everyone.
I've got a bit of a problem with a resize script I am applying to images uploaded. I'm so very very close to it working, I just have a couple of bugs that I can't figure out.
For a better understanding, I'll give you a bit on how the system works..
When displaying the images, their references are coming from a DB, so I loop through the images like this with a requre call to the resize image script.
for($i=0; $i < $num_results; $i++){
$name=mysql_result($result, $i, "image_name"); //name of the picture
$desc=mysql_result($result, $i, "prod_desc"); //the name of description
require('resize_image.php');
Then in an echo statement where the HTML is printed, I am writing the image tag like so...
<img src="files/images/'.$name.'" width="'.$tn_width.'" height="'.$tn_height.'" />
Here is a copy of the resize script, I'll warn you it's kind of long.
<?php
//$name = $HTTP_GET_VARS['name'];
if (!$max_width)
$max_width = 100;
if (!$max_height)
$max_height = 100;
$size = getimagesize('files/images/'.$name);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = imagecreatefromjpeg('files/images/'.$name);
$dst = imagecreate($tn_width,$tn_height);
imagecopyresized($dst, $src, 0, 0, 0, 0, $tn_width,$tn_height,$width,$height);
header('Content-type: image/jpeg');
imagejpeg($dst, null, -1);
imagedestroy($src);
imagedestroy($dst);
?>
Then what happens is sort of odd. The script actually resizes one of the pictures. At one point, it resized all in mozilla, but not in IE (why there are browser issues with php is my guess). Now it only resizes the vertical one correctly. This is the problem though, and probably the reason they don't resize each time, a slew of errors are coming up before the images. Below are the errors.
Warning: imagecreate(): Invalid image dimensions in /home/admin/public_html/clients/weh/resize_image.php on line 31
Warning: imagecopyresized(): supplied argument is not a valid Image resource in /home/admin/public_html/clients/weh/resize_image.php on line 32
Warning: Cannot modify header information - headers already sent by (output started at /home/admin/public_html/clients/weh/accessories.php:74) in /home/admin/public_html/clients/weh/resize_image.php on line 33
Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/admin/public_html/clients/weh/resize_image.php on line 34
Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/admin/public_html/clients/weh/resize_image.php on line 36
Warning: imagecreate(): Invalid image dimensions in /home/admin/public_html/clients/weh/resize_image.php on line 31
Warning: imagecopyresized(): supplied argument is not a valid Image resource in /home/admin/public_html/clients/weh/resize_image.php on line 32
Warning: Cannot modify header information - headers already sent by (output started at /home/admin/public_html/clients/weh/accessories.php:74) in /home/admin/public_html/clients/weh/resize_image.php on line 33
Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/admin/public_html/clients/weh/resize_image.php on line 34
Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/admin/public_html/clients/weh/resize_image.php on line 36
Warning: Cannot modify header information - headers already sent by (output started at /home/admin/public_html/clients/weh/accessories.php:74) in /home/admin/public_html/clients/weh/resize_image.php on line 33
ÿØÿà
I have no clue to why this is happening. It seems to me the ratios and whatnot are correct to resize the image, seeing that it actually does resize the image, just with all those errors.
I'm so close here, can anyone help me out?
Brian