Adding watermark to uploaded images

You can share your Lua Scripts with everybody here.
Post Reply
FTP
Site Admin
Posts: 2104
Joined: Tue Sep 29, 2009 6:09 am

Adding watermark to uploaded images

Post by FTP »

-- Description: Adding watermark to uploaded images using alpha channel
-- Author: Luke
-- Date: 2009-10-19

Code: Select all

do
	require "gd"

	--source image filename
	local filename = string.gsub("%PathName", "\\","/")

	--source image surface
	local im = nil

	--get the file extension
	local suffix = string.lower(string.sub(filename,-4))

	if suffix == ".jpg" or suffix == "jpeg" then 
		im = gd.createFromJpeg(filename)
	elseif suffix == ".png" then
		im = gd.createFromPng(filename)
	elseif suffix == ".gif" then
		im = gd.createFromGif(filename)
	else
		return
	end

	assert(im)

	--create logo surface
	imlogo = gd.createFromPng("d:/mylogo.png")

	--draw transparent(30% opacity) logo on source surface
	sx, sy = imlogo:sizeXY()
	gd.copyMerge(im, imlogo, 10, 10, 0, 0, sx, sy, 30)

	im:png(filename)
end

You may add above lua scripts to the FTP's onFileUploaded event.
Image


Those scirpt uses a external image library "Lua-GD", you can visit their home page at: http://luaforge.net/projects/lua-gd/
We also provide a archived file with "Lua-GD" libs, you can download and unzip it into the working directory of Wing FTP Server. The download URL: https://www.wftpserver.com/bbsres/libgd.zip
Post Reply