Page 1 of 1

saving image to database after rotation

Posted: Tue Feb 15, 2011 4:41 pm
by timoteo
Hi, I've been working on a script to rotate an image downloaded from my database. It works perfectly, however I have not been able to get the image attributes to save the new image. The image echos fine

Code: Select all

echo $imagevar;
Can anyone help me get this script to echo the $filesize, $content and attributes at the bottom of the script. Apart from the photo I can echo nothing else - nothing at all! Thanks...

Code: Select all

$imcontent = $rowid['content'];
		$size = $rowid['size'];
		$type = $rowid['type'];
		$name = $rowid['name'];
		
		$new = imagecreatefromstring($imcontent);
		
		$degrees = 90;
		$rotate = imagerotate($new, $degrees, 0);
		header('Content-type: image/jpeg');
		
		imagejpeg($rotate, 'tmp.jpg');
		$imagefile = "tmp.jpg";
		$image = imagecreatefromjpeg($imagefile);
		ob_start();
		imagejpeg($image);
		$imagevar = ob_get_contents();
		ob_end_clean();
		
		echo $imagevar;
		$filesize = filesize($imagevar);
		echo $filesize;
		if(!get_magic_quotes_gpc()){
		$filename = addslashes($filename);
		}
		
		$fp =fopen($imagevar, 'r');
		$content = fread($fp, $filesize);
		$content = addslashes($content);
		fclose($fp);
		
	
		echo $filesize;
		list($width, $height, $type, $attr) = getimagesize($imagevar);
		
		echo $width;
		echo $height;		
		echo $type;
		echo $attr;

Re: saving image to database after rotation

Posted: Wed Feb 16, 2011 4:31 am
by timoteo
Yes, resolved my own post. Just to let anyone know who might be browsing here.
I just had to use the $imagefile variable rather than the $imagevar variable
This, therefore, was superfluous and not necesary:

Code: Select all

$image = imagecreatefromjpeg($imagefile);
                ob_start();
                imagejpeg($image);
                $imagevar = ob_get_contents();
                ob_end_clean();
                
                echo $imagevar;
Now on my page if someone presses rotate button, I run this script and changes are saved in database. I'm a newbie, if anyone has any comments or criticisms on my solution I would love to hear ... always learning.