Hello,
I have added Jpeg support to TCPDF on adding GetImageSize() function
missing.
In first, i have added them MiniExiftool gem to tcpdf.rb
require 'mini_exiftool'
Then, i have added line 2700, before parsejpg(file) function, the
GetImageSize() function like this :
def GetImageSize(file)
begin
exifs = MiniExiftool.new(file)
response = Array.new
# 0 : image width
response << exifs['imagewidth']
# 1 : image height
response << exifs['imageheight']
# 2 : image type code to complete
imagetype = {"image/gif" => 1,
"image/jpeg" => 2,
"image/png" => 3
}
response << imagetype[exifs['mimetype']]
# 3 : attr for html
response << "height=\"#{exifs['imagewidth']}\" width=
\"#{exifs['imageheight']}\""
# 4 : channels
response << exifs['colorcomponents']
# 5 : bits
response << exifs['bitspersample']
return response
rescue
Error('No exifs informations - GetImageSize: ' + file);
nil
end
end
And then, have modified parsejpg(file) function like this :
#
# Extract info from a JPEG file
# @access protected
#
def parsejpg(file)
a=GetImageSize(file);
if (a.empty?)
Error('Missing or incorrect image file: ' + file);
end
if (a[2]!=2)
Error('Not a JPEG file: ' + file);
end
if (a[4].nil? or a[4]==3)
colspace='DeviceRGB';
elsif (a[4]==4)
colspace='DeviceCMYK';
else
colspace='DeviceGray';
end
bpc=!a[5].nil? ? a[5] : 8;
#Read whole file
data='';
open(file,'rb') do |f|
data<<f.read();
end
#f.close
return {'w' => a[0],'h' => a[1],'cs' => colspace,'bpc' =>
bpc,'f'=>'DCTDecode','data' => data}
end
For the mini_exiftool gem : gem install mini_exiftool
Now, i have a bug too ...
I have to comment the line 19 of environment.rb to have TCPDF
working ... !!!
ActionView::Template::register_template_handler 'rfpdf', RFPDF::View
Error :
Loading development environment (Rails 2.0.2)
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/
dependencies.rb:263:in `load_missing_constant':NameError:
uninitialized constant ActionView::Template
/var/www/
intranet.parisot.com/app/controllers/application.rb:
11:NoMethodError: undefined method `before_init_gettext' for
ApplicationController:Class
but before_init_gettext is defined !!