Chris@1296: # The MIT License Chris@1296: # Chris@1296: # Permission is hereby granted, free of charge, to any person obtaining a copy Chris@1296: # of this software and associated documentation files (the "Software"), to deal Chris@1296: # in the Software without restriction, including without limitation the rights Chris@1296: # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell Chris@1296: # copies of the Software, and to permit persons to whom the Software is Chris@1296: # furnished to do so, subject to the following conditions: Chris@1296: # Chris@1296: # The above copyright notice and this permission notice shall be included in Chris@1296: # all copies or substantial portions of the Software. Chris@1296: # Chris@1296: # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR Chris@1296: # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, Chris@1296: # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE Chris@1296: # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER Chris@1296: # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, Chris@1296: # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN Chris@1296: # THE SOFTWARE. Chris@1296: # Chris@1296: # This implements native php methods used by tcpdf, which have had to be Chris@1296: # reimplemented within Ruby. Chris@1296: Chris@1296: module RFPDF Chris@1296: Chris@1296: # http://uk2.php.net/getimagesize Chris@1296: def getimagesize(filename) Chris@1296: image = Magick::ImageList.new(filename) Chris@1296: Chris@1296: out = Hash.new Chris@1296: out[0] = image.columns Chris@1296: out[1] = image.rows Chris@1296: Chris@1296: # These are actually meant to return integer values But I couldn't seem to find anything saying what those values are. Chris@1296: # So for now they return strings. The only place that uses this at the moment is the parsejpeg method, so I've changed that too. Chris@1296: case image.mime_type Chris@1296: when "image/gif" Chris@1296: out[2] = "GIF" Chris@1296: when "image/jpeg" Chris@1296: out[2] = "JPEG" Chris@1296: when "image/png" Chris@1296: out[2] = "PNG" Chris@1296: when " image/vnd.wap.wbmp" Chris@1296: out[2] = "WBMP" Chris@1296: when "image/x-xpixmap" Chris@1296: out[2] = "XPM" Chris@1296: end Chris@1296: out[3] = "height=\"#{image.rows}\" width=\"#{image.columns}\"" Chris@1296: out['mime'] = image.mime_type Chris@1296: Chris@1296: # This needs work to cover more situations Chris@1296: # I can't see how to just list the number of channels with ImageMagick / rmagick Chris@1296: if image.colorspace.to_s == "CMYKColorspace" Chris@1296: out['channels'] = 4 Chris@1296: elsif image.colorspace.to_s == "RGBColorspace" Chris@1296: out['channels'] = 3 Chris@1296: end Chris@1296: Chris@1296: out['bits'] = image.channel_depth Chris@1296: Chris@1296: out Chris@1296: end Chris@1296: Chris@1296: end