To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / a8 / a8fcb4e60d3d6ca540df4b1fe8b5129d6584c578.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (2.33 KB)

1
# The MIT License
2
#
3
# Permission is hereby granted, free of charge, to any person obtaining a copy
4
# of this software and associated documentation files (the "Software"), to deal
5
# in the Software without restriction, including without limitation the rights
6
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
# copies of the Software, and to permit persons to whom the Software is
8
# furnished to do so, subject to the following conditions:
9
#
10
# The above copyright notice and this permission notice shall be included in
11
# all copies or substantial portions of the Software.
12
#
13
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
16
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
# THE SOFTWARE.
20
#
21
# This implements native php methods used by tcpdf, which have had to be
22
# reimplemented within Ruby.
23

    
24
module RFPDF
25

    
26
  # http://uk2.php.net/getimagesize
27
  def getimagesize(filename)
28
    out = Hash.new
29
    out[2] = ImageScience.image_type(filename)
30
    
31
    image = ImageScience.with_image(filename) do |img|
32
      out[0] = image.width
33
      out[1] = image.height
34
      
35
      # These are actually meant to return integer values But I couldn't seem to find anything saying what those values are.
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.
37
      case out[2]
38
      when "GIF"
39
        out['mime'] = "image/gif"
40
      when "JPEG"
41
        out['mime'] = "image/jpeg"
42
      when "PNG"
43
        out['mime'] = "image/png"
44
      when "WBMP"
45
        out['mime'] = "image/vnd.wap.wbmp"
46
      when "XPM"
47
        out['mime'] = "image/x-xpixmap"
48
      end
49
      out[3] = "height=\"#{image.height}\" width=\"#{image.width}\""
50
      
51
      if image.colorspace == "CMYK" || image.colorspace == "RGBA"
52
          out['channels'] = 4
53
      elsif image.colorspace == "RGB"
54
        out['channels'] = 3
55
      end
56
      
57
      out['bits'] = image.depth
58
      out['bits'] /= out['channels'] if out['channels']
59
    end
60
    
61
    out
62
  end
63
  
64
end