# Mini\_Magick Problem

**URL:** <https://www.ruby-forum.com/t/mini-magick-problem/68612>\
**Category:** Rails\
**Created:** [September 13, 2006, 10:27pm UTC](https://www.ruby-forum.com/t/mini-magick-problem/68612 "2006-09-13T22:27:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [September 13, 2006, 10:27pm UTC](https://www.ruby-forum.com/t/mini-magick-problem/68612/1 "2006-09-13T22:27:47Z")

</div>

I can’t for the life of me figure this out. Been banging my head on  
this since the weekend, and can’t see what I’m doing wrong.

This code works:  
image.resize(“640x480”)  
image.write(path)

I run this and I get the resized file just fine.

This doesnt work at all:  
width = 200  
height = 100  
dimensions = “#{width}x#{height}”

```
image.resize(dimensions)
image.write(path)

```

The second I variablize the parameters the whole thing freaks out with  
this error:  
ImageMagick command (mogrify -width “/tmp/minimagic6355.0”) failed:  
Error Given 256

Anyone have any ideas? I like the idea of using mini\_magick for the  
smaller memory footprint, but much more of this and I need to go to  
RMagick.

---

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [September 14, 2006, 3:37am UTC](https://www.ruby-forum.com/t/mini-magick-problem/68612/2 "2006-09-14T03:37:05Z")

</div>

I know it’s not gonna help, but I’ve just tried your code and it works  
perfectly…

And there is technically no reason why it should not!

---

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [September 14, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/mini-magick-problem/68612/3 "2006-09-14T17:02:03Z")

</div>

Nauhaie N. wrote:

> I know it’s not gonna help, but I’ve just tried your code and it works  
> perfectly…
> 
> And there is technically no reason why it should not!

Wow, this is really weird. If I hard code the dimensions it works fine.  
I’m completely baffled by this one and have no idea where to even start  
looking.

One clue might be the ruby code is inside a class in the lib directory.  
I wonder if that might be causing it a problem.

Versions I’m running:  
Debian 3.1  
Ruby 1.8.4  
Rails 1.1.6  
mini\_magick 1.1.2  
imagemagick 6.2.4

Even if anyone has a guess as to where to start looking, I’d be hugely  
appreciative!

---

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [September 26, 2006, 10:22pm UTC](https://www.ruby-forum.com/t/mini-magick-problem/68612/4 "2006-09-26T22:22:02Z")

</div>

I just ran into a similar problem myself when upgrading from an older  
Mini Magick to version 1.2.0. I think, with the newer Mini\_Magick  
library, the style for retrieving attributes has been changed from:

image.height  
image.width

to:

image[:height]  
image[:width]

so this code:

if (image.width.to\_f/image.height.to\_f) \>= (width.to\_f/height.to\_f)

should probably be changed to:

if (image[:width].to\_f/image[:height].to\_f) \>= (width.to\_f/height.to\_f)

The giveaway for me was this line in my development log:  
MiniMagick::MiniMagickError (ImageMagick command (mogrify -width  
“/tmp/minimagic7060.0”) failed: Error Given 256):

Mini Magick was trying to use width as a mogrify option rather than  
retrieving the image’s width.

---

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [September 14, 2006, 7:58pm UTC](https://www.ruby-forum.com/t/mini-magick-problem/68612/5 "2006-09-14T19:58:28Z")

</div>

Joe C. wrote:

> Nauhaie N. wrote:
> 
> > I know it’s not gonna help, but I’ve just tried your code and it works  
> > perfectly…
> > 
> > And there is technically no reason why it should not!
> 
> Wow, this is really weird. If I hard code the dimensions it works fine.  
> I’m completely baffled by this one and have no idea where to even start  
> looking.
> 
> One clue might be the ruby code is inside a class in the lib directory.  
> I wonder if that might be causing it a problem.
> 
> Versions I’m running:  
> Debian 3.1  
> Ruby 1.8.4  
> Rails 1.1.6  
> mini\_magick 1.1.2  
> imagemagick 6.2.4
> 
> Even if anyone has a guess as to where to start looking, I’d be hugely  
> appreciative!

Ok just for posterity, I found seemingly unrelated code that was the  
problem. High up I had some code that I didn’t include that is causing  
everything to fall apart:  
if (image.width.to\_f/image.height.to\_f) \>= (width.to\_f/height.to\_f)  
#~ dimensions = “#{height}x#{width}”  
#~ else  
#~ dimensions = “#{width}x#{height}”  
end

The second I comment out the if the code works, otherwise I get the  
mogrify error. Now the question is why? I’m guessing something in the  
evaluation is possible touching the image object?
