Page 1 of 1

Unable to open images with imagejpeg() [Solved]

Posted: Thu Jan 11, 2007 4:58 pm
by Jade
Hey there.

I'm working on a site for someone and I've run into a problem. Anytime I try to open the image to write over it I get errors. Both the folder and the image are chmod 777. I've tried looking online for solutions with no luck. I'm running out of ideas, anyone had this problem before?

Code: Select all

function resizeImage($filename)
{
//Figure out image type
$type = substr($filename, (strlen($filename)-4), strlen($filename));

//1/4 of the image size
if (getimagesize($filename) > 20000)
	$percent = 0.25;
else //3/4 of the image size
	$percent = 0.75;

// Set a maximum height and width
$width = 120;
$height = 90;

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);


if ($type == ".jpg" || $type == "jpeg")//jpg image
	$image = imagecreatefromjpeg($filename);
else if ($type == ".gif") //gif inage
	$image = imagecreatefromgif($filename);
else if ($type == ".png") //png image
	$image = imagecreatefrompng($filename);
else
	return "Error!";
	
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

if ($type == ".jpg" || $type == "jpeg")//jpg image
{
	imagejpeg($image_p, "uploads/newimage.jpg", 100);
	return "<img src=\"uploads/newimage.jpg\" />";
}
else if ($type == ".gif") //gif inage
{
	imagegif($image_p, "uploads/newpicture.gif", 100);
	return "<img src=\"uploads/newpicture.gif\" />";
}
else if ($type == ".png") //png image
{
	imagepng($image_p, "uploads/newpicture.png", 100);
	return "<img src=\"uploads/newpicture.png\" />";
}
else
	return "Error!";
}
[/b]

Posted: Thu Jan 11, 2007 5:01 pm
by Kieran Huggins
what errors do you get exactly?

Posted: Thu Jan 11, 2007 5:06 pm
by Jade
Warning: imagejpeg() [function.imagejpeg]: Unable to open 'http://graphicart.com/uploads/newimage.jpg' for writing in /home/stockinv/public_html/graphicart/kernel/functions.php on line 818

Not that the error message helps much....

Posted: Thu Jan 11, 2007 5:09 pm
by feyd
You don't write or call Jade, what's the deal? :)

It really says the url?

Posted: Thu Jan 11, 2007 5:13 pm
by Jade
Lol, I have no clue. No, I took the url out, thats an old error message. Too lazy to refresh the page, after all, that requires clicking...

Posted: Thu Jan 11, 2007 5:19 pm
by Kieran Huggins
Have you tried touching it first?

Code: Select all

if ($type == ".jpg" || $type == "jpeg")//jpg image
{
        touch("uploads/newimage.jpg");
        imagejpeg($image_p, "uploads/newimage.jpg", 100);
        return "<img src=\"uploads/newimage.jpg\" />";
}

Posted: Thu Jan 11, 2007 5:27 pm
by Jade
Great! That worked. Kuddos to you :D