From: John Joyce Date: 2007-07-19T10:47:07+09:00 Subject: Re: Validating an Image file is an image file On Jul 18, 2007, at 7:28 PM, Tim Hunter wrote: > John Joyce wrote: >> Cool, Dan, that looks pretty slick. I certainly couldn't have done >> that so quickly, but I knew what basically was needed. That looks >> like about what I was thinking of conceptually. Very nice and >> clean code! Nice touch with downcasing file extensions too! I hate >> that cameras all like to upcase filenames... (> <)! >> That will probably run a lot lighter than RMagick methods, I'll >> try it out later. I've been fiddling with the RMagick API all >> afternoon. There's a lot of documentation but some of it is >> lacking in clear examples. >> At this point I know how to scale images and keep the aspect ratio >> within a maximum new size, but I'd like to have the final output >> be square with matting on the sides for portrait orientation, >> matting on the top and bottom for landscape orientation, either >> one with the scaled image centered. >> Will this require subsequent compositing after scaling? Or did I >> miss a method somewhere in the docs that does all of this at once? >> >> John Joyce >> > Yes, you'll need to composite the scaled image on top of the > background of your desired size. See my article "Alpha Compositing > - Part 1" [http://rmagick.rubyforge.org/src_over.html]. If you're > making a lot of thumbnails you might also be interested in "Making > Thumbnails with RMagick" [http://rmagick.rubyforge.org/resizing- > methods.html], which compares the performance of all the RMagick > resizing methods. > > Also if you'll tell me which parts of the documentation are lacking > in clear examples I'll see what I can do to fix it. You can always > open a documentation bug in the RMagick bug tracker on RubyForge. > > Also very cool. Thanks. I will check that stuff out. I guess it's just a bit much the first time looking at the API. The main thing I found a bit vague was creating a new Image or ImageList instance. ImageList responds basically as I would expect, but Image doesn't . Initially I was trying: img = Image.read('redzigzag.jpg') Which apparently creates something similar to ImageList. But when trying to use Image methods, I kept getting an error about ...private method ... called for ....[...]:array (the elipses are just leaving out specifics) What I didn't realize I was missing was the [0] in: img = Image.read('redzigzag.jpg')[0] I'm still not quite sure how that is working as part of that statement really, but I know how to get it going anyway. I can certainly see the convenience of using ImageList to batch a bunch of images, but I figured that Image was fine for working out the logic and flow of what I want to do first. The only other truly confusing thing was lack of examples in many method definitions. This is just me, I can "get it" faster when I have a method definition and example with dummy data plugged in. BTW, the RVG stuff looks pretty interesting. I didn't have time to really dig deep into that so much, just skimming. Overall, I especially like the simplicity of reading and writing files with RMagick. I'm just glad I can do it with Ruby instead of PHP, because Ruby is much easier for me to get a clear picture in my mind of what I'm looking at.