Sha256: ff7633d5c9d123dfaa0fcf5a0c14c95749d8d256c79e0ae0dbb77ae1c3a48721

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

# Google App Engine implementation (does this work?)
class ImageVoodoo
  java_import com.google.appengine.api.images.Image
  java_import com.google.appengine.api.images.ImagesService
  java_import com.google.appengine.api.images.ImagesServiceFactory
  java_import com.google.appengine.api.images.Transform

  ImageService = ImagesServiceFactory.images_service

  #--
  # Value Add methods for this backend
  #++

  ##
  # *GAE* Automatically adjust contrast and color levels.
  def i_am_feeling_lucky
    transform(ImagesServiceFactory.make_im_feeling_lucky)
  end

  #--
  # Implementations of standard features
  #++

  class << self
    private

    def with_bytes_impl(bytes)
      image = ImageServicesFactory.make_image(bytes)
      ImageVoodoo.new bytes, image, image.format.to_s.upcase
    end
  end

  private

  def flip_horizontally_impl
    transform(ImagesServiceFactory.make_horizontal_flip)
  end

  def flip_vertically_impl
    transform(ImagesServiceFactory.make_vertical_flip)
  end

  def resize_impl(width, height)
    transform(ImagesServiceFactory.make_resize(width, height))
  end

  def with_crop_impl(left, top, right, bottom)
    transform(ImagesServiceFactory.make_crop(left, top, right, bottom))
  end

  def from_java_bytes
    String.from_java_bytes @src.image_data
  end

  #
  # Make a duplicate of the underlying src image
  #
  def dup_src
    ImageServicesFactory.make_image(from_java_bytes)
  end

  def transform(transform, target=dup_src)
    ImageService.apply_transform(transform, target)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
image_voodoo-0.9.3 lib/image_voodoo/gae.rb
image_voodoo-0.9.2 lib/image_voodoo/gae.rb
image_voodoo-0.9.1 lib/image_voodoo/gae.rb