Skip to content

Instantly share code, notes, and snippets.

@hakunin
Created November 4, 2010 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakunin/662305 to your computer and use it in GitHub Desktop.
Save hakunin/662305 to your computer and use it in GitHub Desktop.
# too bad appengine doesn't honor png transparency in this case
def image
root = System.getProperty('user.dir')
originalImage = ImagesServiceFactory.makeImage(
read(root + '/voucher/test.png'))
c = Composite(ImagesServiceFactory.makeComposite(
originalImage, 0, 0, 1, Composite.Anchor.TOP_LEFT))
#List<Composite> myComposites = new ArrayList<Composite>();
watermarkImage = ImagesServiceFactory.makeImage(
read(root + '/voucher/over_500.png'))
watermark = ImagesServiceFactory.makeComposite(
watermarkImage, 0, 0, 1, Composite.Anchor.BOTTOM_CENTER)
myComposites = ArrayList.new()
myComposites.add(c);
myComposites.add(watermark)
background = Long.parseLong('ffffffff', 16)
imageWithWatermark = ImagesServiceFactory.getImagesService().
composite(
myComposites,
originalImage.getWidth(),
originalImage.getHeight(),
background
)
puts imageWithWatermark.getImageData()
#puts imageWithWatermark.getImageData().getClass.getName
params.response.setContentType('image/png;')
params.respond(imageWithWatermark.getImageData())
end
def read(path:String)
file = File.new(path)
fin = FileInputStream.new(file)
fileContent = byte[int(file.length())]
fin.read(fileContent)
fileContent
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment