Jump to content

Restructuring image script?


Solarpitch

Recommended Posts

Hey Guys,

 

I am using the below script to upload and resize an image if needs be but in the process of trying to make it work, its gone very messy. What would be the optimal way to clean this script up?

 


$image1 = $_FILES['image1']['tmp_name'];
$max = 800;

if($_FILES['image1']['tmp_name'] != ""){

			list($width, $height, $type, $attr) = getimagesize($_FILES['image1']['tmp_name']);

			move_uploaded_file($_FILES['image1']['tmp_name'], $image1file);

			$copy1 = $image1;

			if(($width > $height) && ($width > $max))
			{
				$height = (($height/$width) * $max);
				$width = $max;
				$resize = "true";
			}
			else if (($height > $width) && ($height > $max)) 
			{
				$width = (($width/$height) * $max);
				$height = $max;
				$resize = "true";
			}				

			if ($resize == "true")
			{
				 $newwidth=700;
				 $newheight=($height/$width)*560;

				$src = imagecreatefromjpeg($image1);
			        $tmp=imagecreatetruecolor($tn_width,$tn_height);
				imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

				$image1 = $folder.$timest."AA".$_FILES['image1']['name'];
				imagejpeg($tmp,$image1,100);

				imagedestroy($src);
				imagedestroy($tmp);




			}

	        $destination_width    =    160;
   			$destination_height    =    110;
    			$imagecop1    =    new hft_image($copy1);
    			$sz=getimagesize($copy1);
    			$imagecop1->resize($destination_width,  $destination_height,  '-');
    			$image1thumb = $folder.$timest."AA"."THUMB.jpg";
    			$imagecop1->output_resized($image1thumb,  "JPEG");



		}	

Link to comment
https://forums.phpfreaks.com/topic/77002-restructuring-image-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.