Announcement

Collapse
No announcement yet.

Imagemagick -crop (need help!)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Imagemagick -crop (need help!)

    Hi,

    I need to crop an image to the size of 80x80. The following command resizes my image to 80x60, but I need it to be cropped to 80x80.

    Code:
     Exec("$mogrify -geometry \"80"."x"."80\" -quality \"50\" \"$resized\" \"$resized\"");
    I realize I need to use the crop command but I can't get it to work.

    I looked at the Imagemagick documentation but I still can't figure it out.

    What should the command look like to accomplish my task?

    Thanks,

    Tim
    Five Star Review Script - Add reviews to your website!
    Mixed Martial Arts - Houston MMA Training
    Women's Self-Defense - Courses and DVDs available

  • #3
    Hi,

    Here's the snippet I'm using now:

    PHP Code:
         $command "$mogrify -crop 80x80 $resized"
              
    passthru($command); 
    Now I get an image 80x80 but a whole bunch of them...imgname.jpg.0, imgname.jpg.1, imgname.jpg.2, etc...

    I read that can be prevented by adding the measure from the top left corner but I can't get that to work.

    I'd like to crop the image to 80x80 out from the center of the picture.

    How do I do that?

    Thanks
    Five Star Review Script - Add reviews to your website!
    Mixed Martial Arts - Houston MMA Training
    Women's Self-Defense - Courses and DVDs available

    Comment


    • #4
      Thanks for the links tgillespie. I was able to figure it out. Not sure if this is the best way to do it but it's working for my purposes. If anyone knows a better way, let me know.

      Code:
      //the path and image name renamed to resized for imagemagick to work with while keeping the original
      $resized = "$newfile_name";
      //the name of the final image
      $out = $id ."resized.jpg";
      //name of image to be created by imagemagick
      $output = "/usr/local/httpdocs/images/$out";  
      //resize the image and then save it as temp.jpg
      $command = "/usr/local/bin/convert $resized -resize 50% +profile \"*\" /usr/local/httpdocs/images/temp.jpg";
      passthru($command);
      //crop the temp.jpg file to 80x80 and save it as $idresized.jpg
      $command = "/usr/local/bin/convert /usr/local/httpdocs/images/temp.jpg -gravity Center -crop 80x80+0+0  +profile \"*\" $output";
      passthru($command);
      //delete the temp image.
      unlink("/usr/local/httpdocs/images/temp.jpg");	
      	
      echo "This is the original image:  <img src=/images/$id.jpg> <BR> This is the resized one: <img src=/images/$out>";
      Five Star Review Script - Add reviews to your website!
      Mixed Martial Arts - Houston MMA Training
      Women's Self-Defense - Courses and DVDs available

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...
      X