# Photo rotation

**URL:** <https://www.ruby-forum.com/t/photo-rotation/196679>\
**Category:** Rails\
**Created:** [May 12, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/photo-rotation/196679 "2008-05-12T12:13:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 12, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/photo-rotation/196679/1 "2008-05-12T12:13:56Z")

</div>

hi in my application i have a photo gallery page where i showing all my  
album photos, i want to developed a functionality where i can rotate  
photo there and and saved backed to file system.  
how it is possible ?

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 12, 2008, 12:44pm UTC](https://www.ruby-forum.com/t/photo-rotation/196679/2 "2008-05-12T12:44:01Z")

</div>

RMagick can do this:  
[http://rmagick.rubyforge.org/](http://rmagick.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 12, 2008, 1:13pm UTC](https://www.ruby-forum.com/t/photo-rotation/196679/3 "2008-05-12T13:13:16Z")

</div>

Thorsten M. wrote:

> RMagick can do this:  
> [http://rmagick.rubyforge.org/](http://rmagick.rubyforge.org/)

please send me some clues i haven’t understood from rmagic  
documentation.

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [May 12, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/photo-rotation/196679/4 "2008-05-12T21:08:02Z")

</div>

On May 12, 6:13 am, Sunny B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## hi in my application i have a photo gallery page where i showing all my album photos, i want to developed a functionality where i can rotate photo there and and saved backed to file system. how it is possible ?
> 
> Posted viahttp://www.ruby-forum.com/.

Untested sample code, compressed to a one-liner to get to the  
essentials:

Magick::Image.read(“/path/to/file/to/rotate”).first.rotate!  
(90).write(“/path/to/rotated/file”)

Breakdown and explanation:

Magick::Image.read(“/path/to/your/file”) -  
-Read in file

.first  
-select first layer (unless you are dealing with animated GIF’s or  
something, this is usually the only one)

.rotate!(90)

- I’ll let you guess. Note, unlike regular math, positive angles mean  
clockwise, not counter-clockwise. Note also the bang, which means to  
modify the object in-place, not return a new one, which is why we can  
chain these calls in one line.

.write(“”)

- Write the new image out.

After doing “Magick::Image.read(”/path/to/your/file").first" you have  
an Image object, which is where all the work gets done. I think you  
can follow the API from there, as once you know how to get an Image  
object, all the methods are right there.
