Class: Pruview::Document
- Inherits:
-
Object
- Object
- Pruview::Document
- Defined in:
- lib/pruview/document.rb
Constant Summary collapse
- TMP_DIR =
'/tmp'- PROCESS_FORMAT =
Configurations
'jpg'- GLOBAL_CMD_ARGS =
'-limit memory 500mb'- PSD_EXT =
'.psd'- POSTSCRIPT_EXT =
['.pdf', '.eps', '.ai']
- IMAGE_EXT =
['.bmp', '.gif', '.jpg', '.jpeg', '.png', '.tga', '.tif', '.tiff', '.exr']
Instance Method Summary collapse
-
#initialize(source, target_dir, target_permission = 0666) ⇒ Document
constructor
A new instance of Document.
- #to_jpg(name, width, height, crop = false) ⇒ Object
Constructor Details
#initialize(source, target_dir, target_permission = 0666) ⇒ Document
Returns a new instance of Document.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pruview/document.rb', line 7 def initialize(source, target_dir, =0666) raise Pruview::Exceptions::InvalidError, "Invalid source file: #{source.to_s}" if !File.file?(source) raise Pruview::Exceptions::InvalidError, "Invalid target directory: #{target_dir.to_s}" if !File.directory?(target_dir) raise Pruview::Exceptions::InvalidError, "Document not supported - file extension: " + file_extension(source) if !format_supported?(source) @source = source @target_dir = target_dir @target_permission = @image = process_image(get_image(source)) @tempfile = nil end |
Instance Method Details
#to_jpg(name, width, height, crop = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pruview/document.rb', line 18 def to_jpg(name, width, height, crop = false) scale_img = scale_image(width, height, crop) scale_img.format 'jpg' scale_img. do |img| img.quality '90' img.interlace 'plane' end tmp_target = File.join(TMP_DIR, "#{name.to_s}-#{$$}-#{Time.now.to_i}-#{rand(1000)}.jpg") scale_img.write(tmp_target) FileUtils.chmod(@target_permission, tmp_target) target = File.join(@target_dir, name.to_s + '.jpg') FileUtils.mv(tmp_target, target, :force => true) return target end |