Page 3 of 3

Posted: Sun Jul 08, 2007 10:17 pm
by volka
What's the purpose of createImage() and what is

Code: Select all

//Grab new image
ob_start();
ImageJPEG($image_p);
$image_buffer = ob_get_contents();
ob_end_clean();
ImageDestroy($image_p);
//Create temporary file and write to it
$fp = tmpfile();
fwrite($fp, $image_buffer);
rewind($fp);
supposed to do?

Posted: Sun Jul 08, 2007 10:21 pm
by jiggens
It is suppose to grab the image that is uploaded and recreate it into 2 new files one for a thumbnail another is large image renaming both files and putting them in the logos directory, at least that is what i want it to do.

Posted: Sun Jul 08, 2007 10:22 pm
by jiggens
I probably dont need it anymore because originally i was using ftp to upload the file and using fopen.

Posted: Sun Jul 08, 2007 10:24 pm
by volka
No, the function at best creates one new file. That's why you call it two times..
jiggens wrote:createImage($uploadfile2,100,400,'/homes/html/images/browse/logos/' . $ID . '.jpg');
createImage($uploadfile2,100,160,'/homes/html/images/browse/logos/' . $ID . '-TH.jpg');
anyway...
let's concentrate on

Code: Select all

//Grab new image
ob_start();
ImageJPEG($image_p);
$image_buffer = ob_get_contents();
ob_end_clean();
ImageDestroy($image_p);
//Create temporary file and write to it
$fp = tmpfile();
fwrite($fp, $image_buffer);
rewind($fp);
What does this code snippet do and why?

Posted: Sun Jul 08, 2007 10:37 pm
by jiggens
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


The original code looked like this

Code: Select all

$uploaddir = '/homes/html/images/temp/';
$uploadfile = $uploaddir . basename($_FILES['newMap']['name']);
$uploadfile2 = $uploaddir . basename($_FILES['newLogo']['name']);
$uploadfile3 = '/homes/html/browse/brochures/' . basename($_FILES['newBrochure']['name']);
$uploadfile4 = '/homes/html/images/browse/banners/' .  $ID . ".jpg";
$uploadfile5 = '/homes/html/browse/features/' . basename($_FILES['newFeatures']['name']);

#upload image function	
		function createImage($imgname,$maxh,$maxw,$newname)
		{
		  list($width, $height) = getimagesize($imgname);
		  if ($width < $maxw && $height < $maxh) {
		  	$new_height = $height;
			$new_width = $width;
		  } else {
			$ratio = ($width/$height);
			$new_height = sqrt(10000/$ratio);
			$new_width = $width * ($new_height / $height);
		  } 
		  $image_p = imagecreatetruecolor($new_width, $new_height);
		  $image = imagecreatefromjpeg($imgname);
		  imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);  
			//Grab new image
			ob_start();
			ImageJPEG($image_p);
			$image_buffer = ob_get_contents();
			ob_end_clean();
			ImageDestroy($image_p);
			//Create temporary file and write to it
			$fp = tmpfile();
			fwrite($fp, $image_buffer);
			rewind($fp);
			//Upload new image
			$conn_id = ftp_connect('10.10.101.10');
			ftp_login($conn_id,'xxxx','xxxx');
			ftp_put($conn_id,$newname, $fp, FTP_BINARY);
			fclose($fp);
		}

Create a temp file when creating and than ftp the file to server.

I am not the original we developer, i am just taking a look at this for friend of mine, he asked if i could give a hand so, i really don't know where that code came from or what it is really for.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jul 09, 2007 6:10 am
by volka
You can pass a filename as second parameter to imagejpeg()
http://de2.php.net/imagejpeg wrote:ilename

The path to the saved file. If not set or NULL, the raw image stream will be outputed directly.