summaryrefslogtreecommitdiffstats
path: root/lib/plugins
diff options
context:
space:
mode:
authorEtienne Massip <etienne.massip@gmail.com>2012-07-11 00:14:56 +0000
committerEtienne Massip <etienne.massip@gmail.com>2012-07-11 00:14:56 +0000
commit823ac010c5bc9468ce2326df55f282e4d7a7a923 (patch)
tree25f018571ea02e5fb29db6aeebc04bd4c50b5a7a /lib/plugins
parent0dbe2342268d46ba88e161bc629927f0212a3468 (diff)
downloadredmine-823ac010c5bc9468ce2326df55f282e4d7a7a923.tar.gz
redmine-823ac010c5bc9468ce2326df55f282e4d7a7a923.zip
File handling cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9973 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/rfpdf/lib/core/rmagick.rb7
-rwxr-xr-xlib/plugins/rfpdf/lib/tcpdf.rb45
2 files changed, 29 insertions, 23 deletions
diff --git a/lib/plugins/rfpdf/lib/core/rmagick.rb b/lib/plugins/rfpdf/lib/core/rmagick.rb
index d561047ce..9311ade76 100644
--- a/lib/plugins/rfpdf/lib/core/rmagick.rb
+++ b/lib/plugins/rfpdf/lib/core/rmagick.rb
@@ -57,12 +57,7 @@ module RFPDF
end
out['bits'] = image.channel_depth
- File.open( TCPDF.k_path_cache + File::basename(filename), 'w'){|f|
- f.binmode
- f.print image.to_blob
- f.close
- }
-
+
out
end
diff --git a/lib/plugins/rfpdf/lib/tcpdf.rb b/lib/plugins/rfpdf/lib/tcpdf.rb
index 158964709..be5bd1870 100755
--- a/lib/plugins/rfpdf/lib/tcpdf.rb
+++ b/lib/plugins/rfpdf/lib/tcpdf.rb
@@ -31,6 +31,9 @@
#
#============================================================+
+require 'tempfile'
+require 'core/rmagick'
+
#
# TCPDF Class.
# @package com.tecnick.tcpdf
@@ -86,10 +89,10 @@ class TCPDF
@@k_small_ratio = 2/3.0
cattr_accessor :k_path_cache
- @@k_path_cache = Rails.root.join('tmp').to_s
+ @@k_path_cache = Rails.root.join('tmp')
cattr_accessor :k_path_url_cache
- @@k_path_url_cache = Rails.root.join('tmp').to_s
+ @@k_path_url_cache = Rails.root.join('tmp')
cattr_accessor :decoder
@@ -2060,16 +2063,12 @@ class TCPDF
type.downcase!
if (type == 'jpg' or type == 'jpeg')
info=parsejpg(file);
- elsif (type == 'png' or type == 'gif')
- img = Magick::ImageList.new(file)
- img.format = "PNG" # convert to PNG from gif
- img.opacity = 0 # PNG alpha channel delete
- open( @@k_path_cache + File::basename(file), 'w') do |f|
- f.binmode
- f.print img.to_blob
- end
- info=parsepng( @@k_path_cache + File::basename(file));
- File.delete( @@k_path_cache + File::basename(file))
+ elsif (type == 'png')
+ info=parsepng(file);
+ elsif (type == 'gif')
+ tmpFile = imageToPNG(file);
+ info=parsepng(tmpFile.path);
+ tmpFile.delete
else
#Allow for additional formats
mtd='parse' + type;
@@ -2892,14 +2891,29 @@ class TCPDF
#Read whole file
data='';
- open( @@k_path_cache + File::basename(file),'rb') do |f|
+ open(file,'rb') do |f|
data<<f.read();
end
- File.delete( @@k_path_cache + File::basename(file))
return {'w' => a[0],'h' => a[1],'cs' => colspace,'bpc' => bpc,'f'=>'DCTDecode','data' => data}
end
+ def imageToPNG(file)
+ return unless Object.const_defined?(:Magick)
+
+ img = Magick::ImageList.new(file)
+ img.format = 'PNG' # convert to PNG from gif
+ img.opacity = 0 # PNG alpha channel delete
+
+ #use a temporary file....
+ tmpFile = Tempfile.new(['', '_' + File::basename(file) + '.png'], @@k_path_cache);
+ tmpFile.binmode
+ tmpFile.print img.to_blob
+ tmpFile
+ ensure
+ tmpFile.close
+ end
+
#
# Extract info from a PNG file
# @access protected
@@ -3937,9 +3951,6 @@ class TCPDF
rescue => err
logger.error "pdf: Image: error: #{err.message}"
Write(@lasth, attrs['src'], '', fill);
- if File.file?( @@k_path_cache + File::basename(file))
- File.delete( @@k_path_cache + File::basename(file))
- end
end
end