Strange issue with convert utility
Posted: 2007-11-02T14:39:44-07:00
I have a PHP script that I have used for years to automatically resize uploaded images based on either a defined $max_height or $max_width var. I am developing a site on Hostgator that uses this script, but it now returns a status code of 1 with no details other than that. One thing I have noticed is that the problem is a sporadic one. If I upload an image from my digital camera using this script, it does what it is supposed to, but if I use am image created in PhotoShop, I get the error. I have spend quite a bit of time trying to determine the cause of this issue, but so far I have had no luck.
Hostgator is running ImageMagick 6.3.5 on the server this site is on. Below I have included the first part of the function I am using.
$gpath is the absolute path to the current location of the site files
$conv is the path to convert on the server
$id is the user_id of the person uploading the image to the server
function logo_upload($gpath, $id, $conv)
{
global $_FILES;
$image = $id.".jpg";
//------------------[ Error Checking ]--------------------
if(!$id) $error = "Error Processing form";
if(!$image && !$error) $error = "Please Select an image to uplaod";
//--------------------------------------[ Deal with images ]------------------------------------------------
//Image type check
if(!$error)
{
if($_FILES['logo']['type'] != "image/pjpeg" && $_FILES['logo']['type'] != "image/jpeg") $error = "Error you can only upload a JPG file";
}
//Move file to desired location on the server
if(!$error)
{
$check1 = copy($_FILES['logo']['tmp_name'], "$gpath/images/logos/thumb/$image");
copy($_FILES['logo']['tmp_name'], "$gpath/images/logos/large/$image");
if($check1 == FALSE ) $error = "Could not copy $image..";
}
//Resize the images
if(!$error)
{
//------------------[small]----------------
$max_height = 33;
$current_file = "$gpath/images/logos/thumb/$image";
// Get the current info on the file
$current_size = getimagesize($current_file, $info);
$current_img_width = $current_size[0];
$current_img_height = $current_size[1];
// Determine if the image actually needs to be resized
// and if it does, get the new height for it
if ($current_img_height > $max_height)
{
$too_big_diff_ratio = $current_img_height/$max_height;
$new_img_width = round($current_img_width/$too_big_diff_ratio);
$new_img_height = $max_height;
$make_magick = system("$conv -resize ".$new_img_width."x".$new_img_height." -quality 100 $current_file $current_File", $error);
}
}
Hostgator is running ImageMagick 6.3.5 on the server this site is on. Below I have included the first part of the function I am using.
$gpath is the absolute path to the current location of the site files
$conv is the path to convert on the server
$id is the user_id of the person uploading the image to the server
function logo_upload($gpath, $id, $conv)
{
global $_FILES;
$image = $id.".jpg";
//------------------[ Error Checking ]--------------------
if(!$id) $error = "Error Processing form";
if(!$image && !$error) $error = "Please Select an image to uplaod";
//--------------------------------------[ Deal with images ]------------------------------------------------
//Image type check
if(!$error)
{
if($_FILES['logo']['type'] != "image/pjpeg" && $_FILES['logo']['type'] != "image/jpeg") $error = "Error you can only upload a JPG file";
}
//Move file to desired location on the server
if(!$error)
{
$check1 = copy($_FILES['logo']['tmp_name'], "$gpath/images/logos/thumb/$image");
copy($_FILES['logo']['tmp_name'], "$gpath/images/logos/large/$image");
if($check1 == FALSE ) $error = "Could not copy $image..";
}
//Resize the images
if(!$error)
{
//------------------[small]----------------
$max_height = 33;
$current_file = "$gpath/images/logos/thumb/$image";
// Get the current info on the file
$current_size = getimagesize($current_file, $info);
$current_img_width = $current_size[0];
$current_img_height = $current_size[1];
// Determine if the image actually needs to be resized
// and if it does, get the new height for it
if ($current_img_height > $max_height)
{
$too_big_diff_ratio = $current_img_height/$max_height;
$new_img_width = round($current_img_width/$too_big_diff_ratio);
$new_img_height = $max_height;
$make_magick = system("$conv -resize ".$new_img_width."x".$new_img_height." -quality 100 $current_file $current_File", $error);
}
}