annotate .svn/pristine/a8/a8fcb4e60d3d6ca540df4b1fe8b5129d6584c578.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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