• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

Why does my file not resize?

I am trying to upload and resize a file. Can you tell me why my file does not resize. It uploads fine but the resize does not work.
$property_id="223";
error_reporting(E_ALL);
 
 
if (isset($_FILES['image'])) {
 
if(!(is_dir('../../property_images/$property_id')))
{
echo "hello";
mkdir("../../property_images/$property_id/", 0700);
 
}
 
list($width, $height, $type, $w) = getimagesize($_FILES['userfile']['tmp_name']);
 
$imageinfo = getimagesize($_FILES['userfile']['tmp_name']);
         
echo $width=$imageinfo[0];
echo $height=$imageinfo[1];
 
 
$newwidth = 300;
$newheight = 200;
 
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($_FILES['image']['tmp_name']);
 
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, 400, 300, $width, $height);
 
 
 
	$ftmp = $_FILES['image']['tmp_name'];
	$oname = $_FILES['image']['name'];
	$fname = "../../property_images/$property_id/".$_FILES['image']['name'];
	if(move_uploaded_file($ftmp, $fname)){
 
// do something
 
 
}

Open in new window

0
roscoeh23
Asked:
roscoeh23
1 Solution
 
RoonaanCommented:
You probably need to do a imagejpeg($thumb, 'path/to/your/new/thumb.jpg') in order for a thumbnail file to be stored.

It might also be that for the $source image, you need to use the image ?fter you moved it using move_uploaded_file, rather than before.

What warning or message do you get at this stage that tells you that thumbnailing fails?

Kind regards

-r-
0
 
dr_dedoCommented:
in line 7 you should use douple quates if you are to put vriables inside string
if(!(is_dir("../../property_images/$property_id")))
also, try this function to resize jpg pics, through to it image source ($_FILES['image']['tmp_name']) , where to save the new created image, desired width and height can be either automatically calculated keeping aspect ratio or you can specify it
function resizePic ($src,$target,$width,$height=0){
	$allowedPics = array('.jpg','jpeg');
	$ext = strtolower(substr($src,strrpos($src,'.')));
	if (in_array($ext,$allowedPics)){
		$srcImage = ImageCreateFromJPEG ($src);
		$orginalW = imagesx($srcImage);
		$orginalH = imagesy($srcImage);
		$ratio = $orginalW/$orginalH;
		$quality = 60;
		$height = (!$height) ? $width/$ratio : $height;
		$image  = ImageCreateTrueColor($width,$height);
		imagecopyresized($image,$srcImage,0,0,0,0,$width,$height,$orginalW,$orginalH);
		imageJPEG($image,$target,$quality);
	} else {
		die ("unsupported image");
	}
}
resizePic($_FILES['image']['tmp_name'] ,$_FILES['image']['name'],300);

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now