Hi, I'm trying an image resizing peice of PHP at the moment and I'm having a nightmare with it. I keep getting either
"Warning: imagecopyresampled(): supplied argument is not a valid Image resource"

or a load of nonsense like

"ÿÛ&#65533;C&#65533; $.' ",#(7),01444'9=82<.342ÿÛ&#65533;C •–—˜™š¢£¤¥¦§¨©ª²³´µ"

The code is:

<?php
require('../../includes/globals.php');
$image_id = $_GET['image_id']; 
$result = mysql_query("SELECT news_image FROM tbl_news WHERE news_id = '$image_id'");
	while($row = mysql_fetch_array($result)){
		$image = "http://www.theipp.co.uk/images/news/".$row['news_image']."";
		$size = getimagesize($image);
		$width = $size[0];
		$height = $size[1];
		$imgw = 120;	// Sets the width of the thumbnail
		$imgh = $height / $width * $imgw;
		$thumb = imagecreatefromjpeg($image);
		imagecopyresampled($thumb,$image,0,0,0,0,$imgw,$imgh,$width,$height);
		$out = imagejpeg($thumb);
		header("content-type: image/jpeg");
		echo $out;
		echo $image;
}
?>

Thanks

    one image per page. if you send more you break the encoding. I suggest you make a master page calling the image output script with params.

      The way it "should" work is by using the <img> tag. The code is run everytime an image is displayed.

      eg. <img src="thumbs.php?image_id=news_id">.

      I've done it before using BLOBs but that isn't an option this time.

        you should try to make sure no output is sent with ob_start and ob_flush. Also, why do you output $out AND $image?

          Image is so I can view the image path that is generated.

            try commenting that line. it breaks the image encoding and shows gibberish.

              hmm $image in the imagecopyresampled call is a string path to the image and not an image resource. I think there is something to look into there too.

                I've managed to get it to output either a thumbnail of a black square or a full size version of the image. The code for the full sized image is:

                	$image = "http://www.theipp.co.uk/images/news/1.jpg";
                		$size = @getimagesize($image);
                		$width = $size[0];
                		$height = $size[1];
                		$imgw = 120;	// Sets the width of the thumbnail
                		$imgh = $height / $width * $imgw;
                		$thumb = @imagecreatefromjpeg($image);
                		@imagecopyresized($thumb,$image,0,0,0,0,$imgw,$imgh,$width,$height);
                		header("content-type: image/jpeg");
                		@imagejpeg($thumb);
                  Write a Reply...