# code: # * George Moschovitis # * Elias Athanasopoulos # # (c) 2004 Navel, all rights reserved. # $Id: gfx.rb 101 2004-10-22 12:35:39Z gmosx $ module N # = GfxUtils # # General graphics utilities collection. # # === Design: # # A simple wrapper around ImageMagick. # # Implement as a module to avoid class polution. You can # still Ruby's advanced features to include the module in your # class. Passing the object to act upon allows to check for nil, # which isn't possible if you use self. # # module GfxUtils # === Input: # width, height = dimensions for the scaled image. # def self.create_thumbnail(src, dest, width, height) # gmosx: [0] selects the 1st frame in case of animated gifs. # gmosx: SOS!!! the +profile "*" is need to strip metadata that # fuckup the internet explorer! if (dest =~ /jpg$/i) or (File.stat(src).size > 60000) # keep only the first frame system %|convert +profile "*" +compress -scale '#{width}x#{height}>' -antialias #{src}[0] #{dest}| else system %|convert +profile "*" +compress -scale '#{width}x#{height}>' -antialias #{src} #{dest}| end end # Use ImageMagick to grab the EXIF data # contained in a jpeg file and store it to a # hash: EXIF field => EXIF value. # # A sample EXIF table: # # Make=Canon # Model=Canon PowerShot S110 # Orientation=1 # X Resolution=180/1 # YResolution=180/1 # ResolutionUnit=2 # DateTime=2002:05:16 21:02:36 # YCbCrPositioning=1 # ExifOffset=196 # ExposureTime=1/80 # FNumber=28/10 # ExifVersion=0210 # DateTimeOriginal=2002:05:16 21:02:36 # DateTimeDigitized=2002:05:16 21:02:36 # ComponentsConfiguration=... # CompressedBitsPerPixel=3/1 # ShutterSpeedValue=202/32 # ApertureValue=95/32 # ExposureBiasValue=0/3 # MaxApertureValue=194698/65536 # SubjectDistance=772/1000 # MeteringMode=5 # Flash=1 # FocalLength=173/32 # MakerNote=. # UserComment= # FlashPixVersion=0100 # ColorSpace=1 # ExifImageWidth=1600 # ExifImageLength=1200 # InteroperabilityOffset=1328 # unknown=R98 # unknown=0100 # unknown=1600 # unknown=1200 # FocalPlaneXResolution=1600000/206 # FocalPlaneYResolution=1200000/155 # FocalPlaneResolutionUnit=2 # SensingMethod=2 # FileSource=. # def self.grab_exif(path) info = %x|identify -format "%[EXIF:*]" #{path}|.split("\n") exif = {} info.each { |l| tag, value = l.split("=") exif[tag] = value } unless exif.empty? return exif else return nil end end end end # module