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