Unable to open images with imagejpeg() [Solved]
Posted: Thu Jan 11, 2007 4:58 pm
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?
[/b]
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!";
}