class DynamicImage::ImageProcessor
ImageProcessor
¶ ↑
This is the image processing pipeline.
Example:¶ ↑
DynamicImage::ImageProcessor .new(file) .crop(crop_start, crop_size) .resize(size) .convert(:jpeg) .read
Attributes
Public Class Methods
Source
# File lib/dynamic_image/image_processor.rb, line 27 def initialize(image, target_format: nil) if image.is_a?(Vips::Image) @image = image @target_format = target_format else reader = DynamicImage::ImageReader.new(image) @image = screen_profile(reader.read.autorot) @target_format = reader.format end end
Public Instance Methods
Source
# File lib/dynamic_image/image_processor.rb, line 39 def convert(new_format) unless new_format.is_a?(DynamicImage::Format) new_format = DynamicImage::Format.find(new_format) end if frame_count > 1 && !new_format.animated? self.class.new(extract_frame(0), target_format: new_format) else self.class.new(image, target_format: new_format) end end
Convert the image to a different format.
Source
# File lib/dynamic_image/image_processor.rb, line 51 def read tempfile = Tempfile.new(["dynamic_image", target_format.extension], binmode: true) tempfile.close write(tempfile.path) tempfile.open tempfile.read ensure tempfile.close end
Returns the image data as a binary string.
Source
# File lib/dynamic_image/image_processor.rb, line 63 def size Vector2d.new( image.get("width"), image.get( image.get_fields.include?("page-height") ? "page-height" : "height" ) ) end
Returns the image size as a Vector2d.
Source
# File lib/dynamic_image/image_processor.rb, line 73 def write(path) image.write_to_file(path, **target_format.save_options) end
Write the image to a file.
Private Instance Methods
Source
# File lib/dynamic_image/image_processor.rb, line 79 def apply(new_image) self.class.new(new_image, target_format:) end
Source
# File lib/dynamic_image/image_processor.rb, line 83 def blank_image image.draw_rect([0.0, 0.0, 0.0, 0.0], 0, 0, image.get("width"), image.get("height"), fill: true) end