On Fri, 15 Feb 2019 07:56:31 +0100
Lutz Haseloff <lutz.hasel...@toppkieker.info> wrote:

> First i tried the grph-downsample.lua script.
> Unfortunately i get an error message
> grph-downsample.lua:31: bad argument #2 to 'format' (number has no
> integer representation) See attached log file.

I remember that error. The script worked up to a particular context
version. I believe a Lua upgrade broke it. The version attached
should work.

Marco
if not modules then modules = { } end modules ['t-downsample'] = {
  version   = 1.001,
  comment   = "companion to grph-inc.mkiv",
  author    = "Peter Münster",
  copyright = "PRAGMA ADE / ConTeXt Development Team",
  license   = "see context related readme files"
}

local format = string.format
-- figures.cachepaths.path = "cache" -- should be setup-option
local function sample_down(oldname, newname, resolution)
	local request = figures.current().request
	local width = request.width
	local height = request.height
	if resolution == "" or (not width and not height) then
		print(format("Nothing to do: %s, %s, %s", oldname, newname, resolution))
		return
	end
	local inch = 72.27
	local image = img.scan{filename = oldname}
	local xy = image.xsize / image.ysize
	if not width then
		width = height * xy / 65536
	end
	if not height then
		height = width / xy / 65536
	end
	local xsize = resolution * width / inch
	local ysize = resolution * height / inch
	if xsize < image.xsize or ysize < image.ysize then
		local s = format("gm convert -strip -resize %dx%d %s %s",
		xsize, ysize, oldname, newname)
		print("Conversion: " .. s)
		os.execute(s)
	else
		print(format("Nothing to do: %s, %s, %s", oldname, newname, resolution))
		print(format("xsize = %d, ysize = %d", xsize, ysize))
	end
end

local formats = {"png", "jpg", "gif"}

for _, s in ipairs(formats) do
	figures.converters[s] = figures.converters[s] or {}
	figures.converters[s]["lowres." .. s] = sample_down
end
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to