local thumb
thumb = function(img, size_str, output)
if type(img) == "string" then
img = assert(load_image(img))
end
local src_w, src_h = img:get_width(), img:get_height()
local opts = parse_size_str(size_str, src_w, src_h)
if opts.center_crop then
img:resize_and_crop(opts.w, opts.h)
elseif opts.crop_x then
img:crop(opts.w, opts.h, opts.crop_x, opts.crop_y)
else
img:resize(opts.w, opts.h)
end
local ret
if output then
ret = img:write(output)
else
ret = img:get_blob()
end
img:destroy()
return ret
end
thumb(input_fname, size_str, out_fname=nil)
Loads and resizes image. Write output to out_fname
if provided, otherwise return image blob. (input_fname
can optionally be an instance of Image
, will get automatically destroyed)