Page 1 of 1

imagejpeg or imagecreatetruecolor

Posted: Sun Mar 05, 2006 1:00 pm
by modplod
Hi all,

for some reason the code below is not writing the image info to the destination file, I have been trying for hours to get it to work, I have check all the vars and they are all being send and all have values, I had it working yesterday, but for some reason I'm missing the spark.

Code: Select all

function makeThumbnailImage($pathToSourceImage,$pathToThumbImage, $thumbHeight, $thumbWidth)
	{
		// get image type
		$imageType = $this->imageis($pathToSourceImage);
		if( $imageType == "jpg"){
			
			// create  output file
			$src_img=imagecreatefromjpeg($pathToSourceImage);
		
			// calutlate the size of out put file, maintaining aspect ratio
			$thumbXY = $this->calcNewSize($imageWidth,$imageHeight,$thumbWidth,$thumbHeight);
			
			$dst_img = @imagecreatetruecolor($thumbXY[0],$thumbXY[1]) or die("Unable to create thumbnail image stream!!<br>Image Name: $fileName");
			
			// write image to Thumb file
			imagejpeg($dst_img,$pathToThumbImage);
			
			// remove image from ram
			imagedestroy($dst_img);
			imagedestroy($src_img);

		}
	}

Posted: Sun Mar 05, 2006 1:41 pm
by John Cartwright
does removing the error suppressant "@" give you an error?

Posted: Sun Mar 05, 2006 2:10 pm
by modplod
Jcart wrote:does removing the error suppressant "@" give you an error?
no it does not.

Posted: Sun Mar 05, 2006 2:11 pm
by John Cartwright
Lets start with the more obvious then, what does

Code: Select all

echo $imageType;
return?

Posted: Sun Mar 05, 2006 2:18 pm
by modplod
It returns a string representing the type of image, in this case all images ARE jpg and

Code: Select all

echo $imageType;
returns "jpg" in this case. gif for gif files, png for png files ect


I think the problem is within this part of the code, but not sure

Code: Select all

// calutlate the size of out put file, maintaining aspect ratio
            $thumbXY = $this->calcNewSize($imageWidth,$imageHeight,$thumbWidth,$thumbHeight);
            
            $dst_img = @imagecreatetruecolor($thumbXY[0],$thumbXY[1]) or die("Unable to create thumbnail image stream!!<br>Image Name: $fileName");
            
            // write image to Thumb file
            imagejpeg($dst_img,$pathToThumbImage);

Posted: Sun Mar 05, 2006 6:17 pm
by modplod
ahaaaa.. I shouldtry this rewrting mu function from scratch more often:)

I seemed to have missed an entire step in the process

anyhow heres my finnished function

Code: Select all

function makeThumbnailImage($pathToSourceImage,$pathToThumbImage, $thumbHeight, $thumbWidth)
	{
		// get image type
		$imageType = $this->imageis($pathToSourceImage);
		if( $imageType == "jpg"){

			// get source image dimentions
			$img_details = getimagesize($pathToSourceImage);

			// calutlate the size of out put file, maintaining aspect ratio
			$thumbXY = $this->calcNewSize($img_details[0],$img_details[1],$thumbWidth,$thumbHeight);

			$dst_img= imagecreatetruecolor($thumbXY[0],$thumbXY[1]);
			
			$src_img = imagecreatefromjpeg($pathToSourceImage);
			
			imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumbXY[0],$thumbXY[1],$img_details[0],$img_details[1]);
			// write image to Thumb file
			imagejpeg($dst_img,$pathToThumbImage);

			// remove image from ram
			imagedestroy($dst_img);
			imagedestroy($src_img);
		}
	}