lib/image_voodoo.rb in image_voodoo-0.9.0 vs lib/image_voodoo.rb in image_voodoo-0.9.1
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
# Before we load image_voodoo we can specify whether we want it to load full
# AWT ala http://www.oracle.com/technetwork/articles/javase/headless-136834.html
# Most users are using image_voodoo as a library for manipulation and do not
# want a full peer window popping up.
unless defined? ImageVoodoo::NEEDS_HEAD
@@ -154,12 +156,12 @@
# Resizes the image to width and height and yields/returns the new image.
def resize(width, height)
target = guard { resize_impl(width, height) }
block_given? ? yield(target) : target
- rescue java.lang.Exception => ne # figure out why this is here at all?
- raise ArgumentError, ne.message
+ rescue java.lang.Exception => e # figure out why this is here at all?
+ raise ArgumentError, e.message
end
# Rotates the image by angle (specified in degrees).
def rotate(angle)
target = guard { rotate_impl(to_radians(angle)) }
@@ -169,10 +171,11 @@
# Saves the image out to path. Changing the file extension will convert
# the file type to the appropriate format.
def save(file)
format = File.extname(file)
return false if format == ''
+
format = format[1..-1].downcase
guard { save_impl(format, JFile.new(file)) }
true
end
@@ -205,9 +208,10 @@
end
# A top-level image loader opens path and then yields/returns the image.
def self.with_image(path)
raise ArgumentError, "file does not exist: #{path}" unless File.file?(path)
+
image = guard { with_image_impl(JFile.new(path)) }
image && block_given? ? yield(image) : image
end
# A top-level image loader reads bytes and then yields/returns the image.