Module: Gluttonberg::Library::QuickMagick::Serialization
- Extended by:
- ActiveSupport::Concern
- Included in:
- Image
- Defined in:
- lib/gluttonberg/library/quick_magick/image/serialization.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#save(output_filename) ⇒ Object
(also: #write, #convert)
InstanceMethods saves the current image to the given filename.
-
#save! ⇒ Object
(also: #write!, #mogrify!)
saves the current image overwriting the original image file.
- #to_blob ⇒ Object
Instance Method Details
#save(output_filename) ⇒ Object Also known as: write, convert
InstanceMethods saves the current image to the given filename
34 35 36 37 38 39 40 41 42 |
# File 'lib/gluttonberg/library/quick_magick/image/serialization.rb', line 34 def save(output_filename) result = QuickMagick.exec3 "convert #{command_line} #{QuickMagick.c output_filename}" if @pseudo_image # since it's been saved, convert it to normal image (not pseudo) initialize(output_filename) revert! end return result end |
#save! ⇒ Object Also known as: write!, mogrify!
saves the current image overwriting the original image file
48 49 50 51 52 53 54 |
# File 'lib/gluttonberg/library/quick_magick/image/serialization.rb', line 48 def save! raise QuickMagick::QuickMagickError, "Cannot mogrify a pseudo image" if @pseudo_image result = QuickMagick.exec3 "mogrify #{command_line}" # remove all operations to avoid duplicate operations revert! return result end |
#to_blob ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/gluttonberg/library/quick_magick/image/serialization.rb', line 59 def to_blob tmp_file = Tempfile.new(QuickMagick::random_string) if command_line =~ /-format\s(\S+)\s/ # use format set up by user blob_format = $1 elsif !@pseudo_image # use original image format blob_format = self.format else # default format is jpg blob_format = 'jpg' end save "#{blob_format}:#{tmp_file.path}" blob = nil File.open(tmp_file.path, 'rb') { |f| blob = f.read} blob end |