Author Topic: ImageMagick resize problem  (Read 6044 times)

0 Members and 1 Guest are viewing this topic.

Offline Chad_Peterson

  • album.pl User
  • *
  • Posts: 2
  • Karma: +0/-0
  • There's no place like 127.0.0.1
ImageMagick resize problem
« on: January 14, 2005, 12:24:12 »
Attached below is the script I'm trying to use to allow the uploading and resizing of an image... The script that is currently being used for the same purpose uses GD but my host only has v1.6 installed and as such there is no "createresambpled" function available.  That being said, I am redoing the script to make use of ImageMagice which is installed and on the latest version.  The image is being uploaded properly and ends up in the right folder, I just cant seem to get the convert function to work.  I've checked that paths are correct (fileexists) and the path to imagemagick is correct - but to no avail... am I missing something - I'm stumped... 

I've also tried relative paths for the images upload and that didn't work either.

Thanks in advance for any light that can be shed on this.

Code below

<?
require("../pagebuilder.php");
Root();

//delete below when done testing
////////////////////////////////
$CrewID = "99";
////////////////////////////////

// Define the $base_dir & imagemagick path
$impath = "/usr/X11R6/bin/";
$temp_dir = "/var/www/html/images/crew/";

//move from temp to folder
$userfile = $_FILES['image']['tmp_name'];
$upfile = "../../images/crew/".$CrewID.".jpg";
move_uploaded_file($userfile, $upfile);
chmod($upfile, 0777);

//get maximum image size from pagebuilder.php
$MIS = $MaxImageSize;
if ($MIS == "") { $MIS = 240; };

// Set the temp filename
$temp_file = $CrewID."_sm.jpg";

//get image attributes
$image_attr = getimagesize($upfile);

// Get the percentage required to resize the image
if ($image_attr[0] > $image_attr[1]) {
  $percentage = ($MIS / $image_attr[0]);
} else {
  $percentage = ($MIS / $image_attr[1]);
}

$new_w = $image_attr[0] * $percentage;
$new_h = $image_attr[1] * $percentage;

$new_w = (int) $new_w;
$new_h = (int) $new_h;

// Create the output file
exec($impath."convert -resize ".$new_w."x".$new_h." ".$upfile." ".$temp_dir.$temp_file);

echo "<DIV align=\"center\"><B>Item updated.  Image(s), if any, were resized.  Click <a href=\"./index.php\">[HERE][/url] to return to the menu.</div>"
?>

Offline Mike Bobbitt

  • album.pl Author
  • Administrator
  • I Spend Too Much Time Here
  • *****
  • Posts: 3381
  • Karma: +35/-2
    • Mike's Development Archive
Re: ImageMagick resize problem
« Reply #1 on: January 14, 2005, 14:10:58 »
Do you have shell access? If so, add this debug line to output the commad:

Code: [Select]
// Create the output file
print($impath."convert -resize ".$new_w."x".$new_h." ".$upfile." ".$temp_dir.$temp_file);
exec($impath."convert -resize ".$new_w."x".$new_h." ".$upfile." ".$temp_dir.$temp_file);

And then run the command as it's printed in your shell. If it works there but not in the script, I'd suspect permissions or security lockdown for PHP running shell commands. If it doesn't work, you should get an error message which will help diagnose from there...

Offline Chad_Peterson

  • album.pl User
  • *
  • Posts: 2
  • Karma: +0/-0
  • There's no place like 127.0.0.1
Re: ImageMagick resize problem
« Reply #2 on: January 14, 2005, 14:31:01 »
I do not have shell access (it's a hosted site).  The server is in "safe-mode" which the ops have already told me no-dice on taking out of safe-mode.  From what I'm seeing on this and other forums, the IM may not work in safe-mode (begging the question, why'd they install it?).   Is that true - am I stuck with the old version of GD (at least until they get off their hineys and install the updated version).


Offline frister

  • album.pl Donor
  • album.pl Hacker
  • ****
  • Posts: 230
  • Karma: +42/-0
  • half baked ideas are better than none
    • fristersoft travelogue
Re: ImageMagick resize problem
« Reply #3 on: January 14, 2005, 23:32:07 »
See my post here http://perl.bobbitt.ca/forums/index.php/topic,1261.msg7093.html#msg7093 on how you may be able to issue a convert command and do things even without having direct shell access.


J.J.

Offline frister

  • album.pl Donor
  • album.pl Hacker
  • ****
  • Posts: 230
  • Karma: +42/-0
  • half baked ideas are better than none
    • fristersoft travelogue
Re: ImageMagick resize problem
« Reply #4 on: January 15, 2005, 00:19:23 »
Also, in your php script, have you tried to capure any returned messages in an array, as explained in the php documentation for the exec command? You can then print_r  that array to the screen.