Page 1 of 1

!RESOLVED! imagejpeg() :: checked everything still errors :(

Posted: Fri Mar 25, 2011 2:04 am
by blakewilliams
First post here... :D
First off, advanced thanks to anyone who spends time on this.

Here's the deal:

I'm trying to create a thumbnail of an uploaded user photo. I continue to get the following error:
Warning: imagejpeg() [function.imagejpeg]: Unable to open '/home/v5w3defp/public_html/sprahl.com/private/avatars/' for writing: Is a directory in /home/v5w3defp/public_html/sprahl.com/private/includes/functions.php
After scouring the nets, I've cleared up the possibility of it being a permissions issue (set to 777 for the sake of solving this problem), a safe_mode issue (set to 'off'), or an issue with the path (I think... I'm using $_SERVER['DOCUMENT_ROOT']).

Here are the relevant functions:

Code: Select all

function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
	$newImageWidth = ceil($width * $scale);
	$newImageHeight = ceil($height * $scale);
	$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
	$source = imagecreatefromjpeg($image);
	imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
	imagejpeg($newImage,$thumb_image_name,100);
}
function changePhoto($name){
	$upload_path = $_SERVER['DOCUMENT_ROOT'] . "/private/avatars/"; 
	$large_image_name = $name; 	// New name of the large image
	$thumb_width = "100";	// Width of thumbnail image
	$thumb_height = "100";

	$thumb_image_location = $upload_path.$thumb_image_name;
	$newname = $_SERVER['DOCUMENT_ROOT'] . '/private/user_photos/' . $large_image_name;

	$width = getWidth($newname);
	$height = getHeight($newname);
		
	// Prepare to chop off excess
	if($height > $width){
		$y1 = ($height - $width)/2;
		$x1 = 0;
		$w = $width;
		$h = $width;
	}
	if($width > $height){
		$x1 = ($width - $height)/2;
		$y1 = 0;
		$w = $height;
		$h = $height;
	}
		
	$scale = $thumb_width/$w;	
	$cropped = resizeThumbnailImage($thumb_image_location,$newname,$w,$h,$x1,$y1,$scale);			
}
Any help would be greatly appreciated.

Thanks.

Re: imagejpeg() :: checked everything still errors :(

Posted: Fri Mar 25, 2011 4:05 am
by Darhazer
check the values of $thumb_image_location and $newname
You are using $thumb_image_name; to build location, but this variable is not defined, $name ia assigned to $large_image_name instead.

Re: imagejpeg() :: checked everything still errors :(

Posted: Fri Mar 25, 2011 11:22 am
by pickle
Like the error says, you're trying to open a directory with imagejpeg() when you should be trying to open a file.

It looks like $image_thumb_name is not being built properly & therefore doesn't have the filename in it - just the path.

Re: imagejpeg() :: checked everything still errors :(

Posted: Fri Mar 25, 2011 12:35 pm
by blakewilliams
Thanks to both of you guys for spotting what a long day of coding refused to allow me to. Nothing like a fresh set of eyes to point out the obvious. :)

Cheers.