lib/image_voodoo.rb in image_voodoo-0.3 vs lib/image_voodoo.rb in image_voodoo-0.4

- old
+ new

@@ -121,16 +121,12 @@ def cropped_thumbnail(size) l, t, r, b, half = 0, 0, width, height, (width - height).abs / 2 l, r = half, half + height if width > height t, b = half, half + width if height > width - with_crop(l, t, r, b) do |image| - image.thumbnail(size) do |thumb| - target = ImageVoodoo.new target - block_given? ? yield(target) : target - end - end + target = with_crop(l, t, r, b).thumbnail(size) + block_given? ? yield(target) : target end # # Flips the image horizontally and yields/returns the new image. # @@ -210,22 +206,21 @@ # the new image. # def scale(ratio) new_width, new_height = (width * ratio).to_i, (height * ratio).to_i - resize(new_width, new_height) do |image| - target = ImageVoodoo.new image - block_given? ? yield(target) : target - end + target = resize(new_width, new_height) + block_given? ? yield(target) : target end # # Creates a proportional thumbnail of the image scaled so its longest # edge is resized to size and yields/returns the new image. # def thumbnail(size) - scale(size.to_f / (width > height ? width : height)) + target = scale(size.to_f / (width > height ? width : height)) + block_given? ? yield(target) : target end # # Crops an image to left, top, right, and bottom and then yields/returns the # new image. @@ -301,15 +296,13 @@ # # A top-level image loader opens path and then yields/returns the image. # def self.with_image(file) - readers = ImageIO.getImageReadersBySuffix(File.extname(file)[1..-1]) - raise TypeError, "unrecognized format for #{file}" unless readers.hasNext - image = ImageVoodoo.new ImageIO.read(JFile.new(file)) - block_given? ? yield(image) : image - rescue NativeException => ne - nil + raise ArgumentError, "file does not exist" unless File.file?(file) + buffered_image = ImageIO.read(JFile.new(file)) + image = ImageVoodoo.new(buffered_image) if buffered_image + image && block_given? ? yield(image) : image end # # A top-level image loader reads bytes and then yields/returns the image. #