# Can't crop images using ImageMagick

**URL:** <https://www.ruby-forum.com/t/cant-crop-images-using-imagemagick/144481>\
**Category:** Rails\
**Created:** [July 30, 2008, 1:17am UTC](https://www.ruby-forum.com/t/cant-crop-images-using-imagemagick/144481 "2008-07-30T01:17:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [July 30, 2008, 1:17am UTC](https://www.ruby-forum.com/t/cant-crop-images-using-imagemagick/144481/1 "2008-07-30T01:17:02Z")

</div>

I’m using Attachment\_Fu to save several thumbnails of a photo  
(resizing with ImageMagick)

But when I try to crop them, nothing seems to happen to the file I  
want to drop and no error messages. I check the file timestamp of the  
thumbnail I want to crop and it looks updated. What’s strange is that  
ALL the other thumbnails and the original image’s file timestamps are  
updated to.

Am I missing something here? At one point in this project I thought I  
successfully resized or cropped an image this way, but I can’t seem to  
do it now.

Also, the files are in the shared “system” directory of a Capistrano  
deployed server.

Here’s my code:

require ‘RMagick’

top\_square = params[:top\_square].to\_d  
left\_square = params[:left\_square].to\_d  
width\_square = params[:width\_square].to\_d  
height\_square = params[:height\_square].to\_d

source\_file = “#{RAILS\_ROOT}/public#{@photo.public\_filename}”  
destination\_file = “#{RAILS\_ROOT}/public#{city\_photo.public\_filename}”

img = Magick::Image.read(source\_file).first  
img.crop!(left\_square, top\_square, width\_square, height\_square)  
img.write destination\_file

Thanks,  
Andy

---

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [July 30, 2008, 1:52am UTC](https://www.ruby-forum.com/t/cant-crop-images-using-imagemagick/144481/2 "2008-07-30T01:52:42Z")

</div>

OK, it looks like if I switch the destination file to the same as the  
source file, it works.

But I want to use the full size as the source and then write to a  
thumbnail.

Any ideas?

Thanks,  
Andy
