annotate vendor/plugins/rfpdf/lib/core/rmagick.rb @ 507:0c939c159af4 redmine-1.2

Update to Redmine 1.2.1 on 1.2-stable branch (Redmine SVN rev 6270)
author Chris Cannam
date Thu, 14 Jul 2011 10:32:19 +0100
parents cbce1fd3b1b7
children cbb26bc654de
rev   line source
Chris@441 1 # The MIT License
Chris@441 2 #
Chris@441 3 # Permission is hereby granted, free of charge, to any person obtaining a copy
Chris@441 4 # of this software and associated documentation files (the "Software"), to deal
Chris@441 5 # in the Software without restriction, including without limitation the rights
Chris@441 6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Chris@441 7 # copies of the Software, and to permit persons to whom the Software is
Chris@441 8 # furnished to do so, subject to the following conditions:
Chris@441 9 #
Chris@441 10 # The above copyright notice and this permission notice shall be included in
Chris@441 11 # all copies or substantial portions of the Software.
Chris@441 12 #
Chris@441 13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Chris@441 14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Chris@441 15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Chris@441 16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Chris@441 17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Chris@441 18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Chris@441 19 # THE SOFTWARE.
Chris@441 20 #
Chris@441 21 # This implements native php methods used by tcpdf, which have had to be
Chris@441 22 # reimplemented within Ruby.
Chris@441 23
Chris@441 24 module RFPDF
Chris@441 25
Chris@441 26 # http://uk2.php.net/getimagesize
Chris@441 27 def getimagesize(filename)
Chris@441 28 image = Magick::ImageList.new(filename)
Chris@441 29
Chris@441 30 out = Hash.new
Chris@441 31 out[0] = image.columns
Chris@441 32 out[1] = image.rows
Chris@441 33
Chris@441 34 # These are actually meant to return integer values But I couldn't seem to find anything saying what those values are.
Chris@441 35 # 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@441 36 case image.mime_type
Chris@441 37 when "image/gif"
Chris@441 38 out[2] = "GIF"
Chris@441 39 when "image/jpeg"
Chris@441 40 out[2] = "JPEG"
Chris@441 41 when "image/png"
Chris@441 42 out[2] = "PNG"
Chris@441 43 when " image/vnd.wap.wbmp"
Chris@441 44 out[2] = "WBMP"
Chris@441 45 when "image/x-xpixmap"
Chris@441 46 out[2] = "XPM"
Chris@441 47 end
Chris@441 48 out[3] = "height=\"#{image.rows}\" width=\"#{image.columns}\""
Chris@441 49 out['mime'] = image.mime_type
Chris@441 50
Chris@441 51 # This needs work to cover more situations
Chris@441 52 # I can't see how to just list the number of channels with ImageMagick / rmagick
Chris@441 53 if image.colorspace.to_s == "CMYKColorspace"
Chris@441 54 out['channels'] = 4
Chris@441 55 elsif image.colorspace.to_s == "RGBColorspace"
Chris@441 56 out['channels'] = 3
Chris@441 57 end
Chris@441 58
Chris@441 59 out['bits'] = image.channel_depth
Chris@441 60
Chris@441 61 out
Chris@441 62 end
Chris@441 63
Chris@441 64 end