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);
}
}
Strange issue with convert utility
Strange issue with convert utility
Last edited by galax on 2007-11-02T15:27:20-07:00, edited 1 time in total.
Re: Strange issue with convert utility
Without working my way through all your code have your tried just resizing an image without all the variables etc. using a direct camera version and a PhotoShop version as that will prove the ImageMagick code is OK.
Also you are supposed to read the photo in before working on it so:
Would become
I do not know if the code style below will give you more information on the errors:
Also you are supposed to read the photo in before working on it so:
Code: Select all
$make_magick = system("$conv -resize ".$new_img_width."x".$new_img_height." -quality 100 $current_file $thumb_name", $error);
Code: Select all
$make_magick = system("$conv $current_file -resize ".$new_img_width."x".$new_img_height." -quality 100 $thumb_name", $error);
Code: Select all
<?php
$array=array();
echo "<pre>";
exec("convert input.jpg -resize 100x100 Output.jpg 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";
?>
Re: Strange issue with convert utility
I just gave that a try but there was no change in the situation. Also I ran a couple test on my local LINUX box on images from my camera and from PhotoShop, and did not have the same issue. My local box is using ImageMagick 6.3.2 .
Re: Strange issue with convert utility
I ended up coming to the conclusion that the problem was with the install of the software on the host server, so I entered a ticket about it. I just got a response from the admins over there confirming my suspicions. They reinstalled imageMagick and now my code is working as it should.
Re: Strange issue with convert utility
I am glad you got it sorted; I have written a bit of php code which will give you a lot of information about your installation:
There are rw+ etc. against different image formats; I do not know what they mean fully but I assume the PhotoShop format must be blank ?
Code: Select all
<?php
// Build the array of items to be used
exec("convert convert -list list", $IMarray, $code);
// Start the loop to find and display the results
foreach ($IMarray as $value) {
echo "<br>system (\"convert -list $value\")";
echo "<pre>";
system("convert -list $value");
echo "</pre><hr>";
}
?>
Re: Strange issue with convert utility
I wish I would have had a function like that while I was having the issue originally, though I suspect you are right to some extent. There was definitely something different about jpg files created by PhotoShop that was related to this issue. And since no real error was coming back from ImageMagick, I was basically just left frustrated and without resolution. I'm just glad that the admins over at the host were willing to actually test the issue and look into a resolution. Of course I'm not sure they had much choice since the ticket I submitted to them was a good six paragraphs of information about the issue, what I had tried to resolve, samples of code and explicit instructions on how to test the situation. I may have gave them all of that info simply because I used to do support back in the day. So I wanted to reduce the chance that they were going to return my email with the typical , did you try this or did you try that crap. Anyway, thanks guys for the assistance I did get from this forum. Once I complete this project I am working on, I will post a link here so that you guys can check it out. I would like to see what you guys think about it.