* setupexternalfigures and resoĺution @ 2022-09-01 8:44 juh+ntg-context--- via ntg-context 2022-09-01 8:51 ` Henning Hraban Ramm via ntg-context 0 siblings, 1 reply; 10+ messages in thread From: juh+ntg-context--- via ntg-context @ 2022-09-01 8:44 UTC (permalink / raw) To: mailing list for ConTeXt users; +Cc: juh+ntg-context Hi, what is resolution meant to do? Whatever I insert as resolution, I get no change. \setupexternalfigure[location={default,local},resolution=30] \starttext \externalfigure[hacker] \stoptext What am I missing? TIA juh ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: setupexternalfigures and resoĺution 2022-09-01 8:44 setupexternalfigures and resoĺution juh+ntg-context--- via ntg-context @ 2022-09-01 8:51 ` Henning Hraban Ramm via ntg-context 2022-09-01 8:56 ` Henning Hraban Ramm via ntg-context ` (2 more replies) 0 siblings, 3 replies; 10+ messages in thread From: Henning Hraban Ramm via ntg-context @ 2022-09-01 8:51 UTC (permalink / raw) To: juh+ntg-context--- via ntg-context; +Cc: Henning Hraban Ramm [-- Attachment #1: Type: text/plain, Size: 653 bytes --] Am 01.09.22 um 10:44 schrieb juh+ntg-context--- via ntg-context: > > Hi, > > what is resolution meant to do? > > Whatever I insert as resolution, I get no change. > > \setupexternalfigure[location={default,local},resolution=30] > \starttext > \externalfigure[hacker] > \stoptext > > What am I missing? The resolution parameter is still not used by default ConTeXt, sorry. But you can use it with the attached lua file like: \loadluafile[grph-downsample] \doifmodeelse{print}{% \def\Resolution{300} }{% \def\Resolution{96} }% \setupexternalfigures[ %directory={./Logos,img}, conversion=lowres.jpg, resolution=\Resolution, ] Hraban [-- Attachment #2: grph-downsample.lua --] [-- Type: text/plain, Size: 2771 bytes --] if not modules then modules = { } end modules ['grph-downsample'] = { version = 1.100, comment = "companion to grph-inc.mkiv", author = "Peter Münster", -- adapted to LMTX by Hraban copyright = "PRAGMA ADE / ConTeXt Development Team", license = "see context related readme files" } assert(not figures.getinfo2) figures.getinfo2 = function(name, page) -- [ [NTG-context] Pdf info with Lua/Ctx API ] if type(name) == "string" then name = { name = name, page = page } end if name.name then local data = figures.push(name) local info = figures.identify() if info.status.status ~= 0 then figures.check() -- !Counts pages here! end figures.pop() return --data info end end local format = string.format -- figures.cachepaths.path = "cache" -- should be setup-option local function sample_down(oldname, newname, resolution) print("DOWNSAMPLE sample_down " .. oldname .. " to " .. newname) local request = figures.current().request local width = request.width local height = request.height if resolution == "" then -- or (not width and not height) then print(format("DOWNSAMPLE Nothing to do: %s, %s, %s dpi, %s x %s px", oldname, newname, resolution, width, height)) return end local TEXpt = 65536 local inch = 72.27 -- MkIV: -- local image = img.scan{filename = oldname} -- LMTX: local image = figures.getinfo(oldname,1) image = image.status.private local xy = image.xsize / image.ysize if (not width and not height) then -- no size requested? use default width width = 300 * TEXpt end if not width then height = height / TEXpt width = height * xy end if not height then width = width / TEXpt height = width / xy end width = math.floor(width) height = math.floor(height) print(format("DOWNSAMPLE image size %dx%dpx. requested %dx%d?", image.xsize, image.ysize, width, height)) local xsize = math.floor(resolution * width / inch) local ysize = math.floor(resolution * height / inch) print(format("DOWNSAMPLE size %d x %d to %d x %d", image.xsize, image.ysize, xsize, ysize)) if xsize < image.xsize or ysize < image.ysize then local s = format("gm convert -resize %dx%d -resample %dx%d %s %s", xsize, ysize, resolution, resolution, oldname, newname) print("DOWNSAMPLE Conversion: " .. s) os.execute(s) else print(format("DOWNSAMPLE Nothing to do: %s, %s, %s dpi, %d x %d px", oldname, newname, resolution, width, height)) print(format("DOWNSAMPLE 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 [-- Attachment #3: Type: text/plain, Size: 496 bytes --] ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: setupexternalfigures and resoĺution 2022-09-01 8:51 ` Henning Hraban Ramm via ntg-context @ 2022-09-01 8:56 ` Henning Hraban Ramm via ntg-context 2022-09-01 10:37 ` juh+ntg-context--- via ntg-context 2022-09-01 11:43 ` juh+ntg-context--- via ntg-context 2022-09-02 8:39 ` Keith McKay via ntg-context 2 siblings, 1 reply; 10+ messages in thread From: Henning Hraban Ramm via ntg-context @ 2022-09-01 8:56 UTC (permalink / raw) To: ntg-context; +Cc: Henning Hraban Ramm Am 01.09.22 um 10:51 schrieb Henning Hraban Ramm via ntg-context: > Am 01.09.22 um 10:44 schrieb juh+ntg-context--- via ntg-context: >> >> Hi, >> >> what is resolution meant to do? >> What am I missing? > > The resolution parameter is still not used by default ConTeXt, sorry. > > But you can use it with the attached lua file like: This works also: \startluacode local function downsampler(oldname, newname, resolution) if not resolution or resolution == "" then resolution = 72 end local cmd = string.format( [[gm convert -resample %ix%i %s %s]], resolution, resolution, oldname, newname) os.execute(cmd) end -- Set the PDF and default JPEG converters to the above function. figures.converters.jpg.pdf = downsampler figures.converters.jpg.default = downsampler \stopluacode I didn’t manage to plug this into the "conversion" mechanism. Hraban ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: setupexternalfigures and resoĺution 2022-09-01 8:56 ` Henning Hraban Ramm via ntg-context @ 2022-09-01 10:37 ` juh+ntg-context--- via ntg-context 2022-09-01 13:05 ` Henning Hraban Ramm via ntg-context 0 siblings, 1 reply; 10+ messages in thread From: juh+ntg-context--- via ntg-context @ 2022-09-01 10:37 UTC (permalink / raw) To: ntg-context; +Cc: juh+ntg-context Hi Hraban, Am 01.09.22 um 10:56 schrieb Henning Hraban Ramm via ntg-context: > \startluacode > local function downsampler(oldname, newname, resolution) > if not resolution or resolution == "" then > resolution = 72 > end > local cmd = string.format( > [[gm convert -resample %ix%i %s %s]], > resolution, resolution, oldname, newname) > os.execute(cmd) > end > > -- Set the PDF and default JPEG converters to the above function. > figures.converters.jpg.pdf = downsampler > figures.converters.jpg.default = downsampler > \stopluacode > > I didn’t manage to plug this into the "conversion" mechanism. Thanks a lot. With this I get 5.9MB instead of 13MB. Maybe I can skip postprocessing the pdf file with ps2pdf. From an error message I guess that this script also tries to downsample png files. Is that correct? juh ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: setupexternalfigures and resoĺution 2022-09-01 10:37 ` juh+ntg-context--- via ntg-context @ 2022-09-01 13:05 ` Henning Hraban Ramm via ntg-context 0 siblings, 0 replies; 10+ messages in thread From: Henning Hraban Ramm via ntg-context @ 2022-09-01 13:05 UTC (permalink / raw) To: juh+ntg-context--- via ntg-context; +Cc: Henning Hraban Ramm Am 01.09.22 um 12:37 schrieb juh+ntg-context--- via ntg-context: > Hi Hraban, > > Am 01.09.22 um 10:56 schrieb Henning Hraban Ramm via ntg-context: >> \startluacode >> local function downsampler(oldname, newname, resolution) >> if not resolution or resolution == "" then >> resolution = 72 >> end >> local cmd = string.format( >> [[gm convert -resample %ix%i %s %s]], >> resolution, resolution, oldname, newname) >> os.execute(cmd) >> end >> >> -- Set the PDF and default JPEG converters to the above function. >> figures.converters.jpg.pdf = downsampler >> figures.converters.jpg.default = downsampler >> \stopluacode >> >> I didn’t manage to plug this into the "conversion" mechanism. > > Thanks a lot. With this I get 5.9MB instead of 13MB. > > Maybe I can skip postprocessing the pdf file with ps2pdf. > > From an error message I guess that this script also tries to downsample > png files. Is that correct? According to the sources it should only attack JPEGs. Hraban ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: setupexternalfigures and resoĺution 2022-09-01 8:51 ` Henning Hraban Ramm via ntg-context 2022-09-01 8:56 ` Henning Hraban Ramm via ntg-context @ 2022-09-01 11:43 ` juh+ntg-context--- via ntg-context 2022-09-01 13:04 ` Henning Hraban Ramm via ntg-context 2022-09-02 8:39 ` Keith McKay via ntg-context 2 siblings, 1 reply; 10+ messages in thread From: juh+ntg-context--- via ntg-context @ 2022-09-01 11:43 UTC (permalink / raw) To: ntg-context; +Cc: juh+ntg-context Am 01.09.22 um 10:51 schrieb Henning Hraban Ramm via ntg-context: > \loadluafile[grph-downsample] > \doifmodeelse{print}{% > \def\Resolution{300} > }{% > \def\Resolution{96} > }% > > \setupexternalfigures[ > %directory={./Logos,img}, > conversion=lowres.jpg, > resolution=\Resolution, > ] With the script I get strange results. I am not sure whether the resolution is correctly calculated. And I am wondering what the script is doing with png files. juh ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: setupexternalfigures and resoĺution 2022-09-01 11:43 ` juh+ntg-context--- via ntg-context @ 2022-09-01 13:04 ` Henning Hraban Ramm via ntg-context 2022-09-01 17:22 ` juh+ntg-context--- via ntg-context 0 siblings, 1 reply; 10+ messages in thread From: Henning Hraban Ramm via ntg-context @ 2022-09-01 13:04 UTC (permalink / raw) To: juh+ntg-context--- via ntg-context; +Cc: Henning Hraban Ramm Am 01.09.22 um 13:43 schrieb juh+ntg-context--- via ntg-context: > Am 01.09.22 um 10:51 schrieb Henning Hraban Ramm via ntg-context: > >> \loadluafile[grph-downsample] >> \doifmodeelse{print}{% >> \def\Resolution{300} >> }{% >> \def\Resolution{96} >> }% >> >> \setupexternalfigures[ >> %directory={./Logos,img}, >> conversion=lowres.jpg, >> resolution=\Resolution, >> ] > > With the script I get strange results. I am not sure whether the > resolution is correctly calculated. > > And I am wondering what the script is doing with png files. This one attacks all images, but it doesn’t calculate the final size correctly. Hraban ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: setupexternalfigures and resoĺution 2022-09-01 13:04 ` Henning Hraban Ramm via ntg-context @ 2022-09-01 17:22 ` juh+ntg-context--- via ntg-context 0 siblings, 0 replies; 10+ messages in thread From: juh+ntg-context--- via ntg-context @ 2022-09-01 17:22 UTC (permalink / raw) To: ntg-context; +Cc: juh+ntg-context Am 01.09.22 um 15:04 schrieb Henning Hraban Ramm via ntg-context: > Am 01.09.22 um 13:43 schrieb juh+ntg-context--- via ntg-context: >> Am 01.09.22 um 10:51 schrieb Henning Hraban Ramm via ntg-context: >> >>> \loadluafile[grph-downsample] >>> \doifmodeelse{print}{% >>> \def\Resolution{300} >>> }{% >>> \def\Resolution{96} >>> }% >>> >>> \setupexternalfigures[ >>> %directory={./Logos,img}, >>> conversion=lowres.jpg, >>> resolution=\Resolution, >>> ] >> >> With the script I get strange results. I am not sure whether the >> resolution is correctly calculated. >> >> And I am wondering what the script is doing with png files. > > This one attacks all images, but it doesn’t calculate the final size > correctly. For the records. I need a resolution of 240 to get a good looking image. This is more or less the same quality with 150 using the other possibility. After playing around this day I fear that postprocessing with ps2pdf is more predictable and results in a way more tiny file. juh ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: setupexternalfigures and resoĺution 2022-09-01 8:51 ` Henning Hraban Ramm via ntg-context 2022-09-01 8:56 ` Henning Hraban Ramm via ntg-context 2022-09-01 11:43 ` juh+ntg-context--- via ntg-context @ 2022-09-02 8:39 ` Keith McKay via ntg-context 2022-09-02 9:26 ` Henning Hraban Ramm via ntg-context 2 siblings, 1 reply; 10+ messages in thread From: Keith McKay via ntg-context @ 2022-09-02 8:39 UTC (permalink / raw) To: mailing list for ConTeXt users; +Cc: Keith McKay [-- Attachment #1.1: Type: text/plain, Size: 1634 bytes --] Thanks for this code Hraban. I tried this last night and it worked really well. I did have one stumbling block when I noticed that those image files with a space in their names were not found, however renaming without a space solved the problem. Is this a bug or a feature? Thanks Keith McKay On Thu, 1 Sep 2022, 09:52 Henning Hraban Ramm via ntg-context, < ntg-context@ntg.nl> wrote: > Am 01.09.22 um 10:44 schrieb juh+ntg-context--- via ntg-context: > > > > Hi, > > > > what is resolution meant to do? > > > > Whatever I insert as resolution, I get no change. > > > > \setupexternalfigure[location={default,local},resolution=30] > > \starttext > > \externalfigure[hacker] > > \stoptext > > > > What am I missing? > > The resolution parameter is still not used by default ConTeXt, sorry. > > But you can use it with the attached lua file like: > > > \loadluafile[grph-downsample] > \doifmodeelse{print}{% > \def\Resolution{300} > }{% > \def\Resolution{96} > }% > > \setupexternalfigures[ > %directory={./Logos,img}, > conversion=lowres.jpg, > resolution=\Resolution, > ] > > > Hraban > > ___________________________________________________________________________________ > If your question is of interest to others as well, please add an entry to > the Wiki! > > maillist : ntg-context@ntg.nl / > https://www.ntg.nl/mailman/listinfo/ntg-context > webpage : https://www.pragma-ade.nl / http://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : https://contextgarden.net > > ___________________________________________________________________________________ > [-- Attachment #1.2: Type: text/html, Size: 2691 bytes --] [-- Attachment #2: Type: text/plain, Size: 496 bytes --] ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: setupexternalfigures and resoĺution 2022-09-02 8:39 ` Keith McKay via ntg-context @ 2022-09-02 9:26 ` Henning Hraban Ramm via ntg-context 0 siblings, 0 replies; 10+ messages in thread From: Henning Hraban Ramm via ntg-context @ 2022-09-02 9:26 UTC (permalink / raw) To: Keith McKay via ntg-context; +Cc: Henning Hraban Ramm [-- Attachment #1: Type: text/plain, Size: 580 bytes --] Am 02.09.22 um 10:39 schrieb Keith McKay via ntg-context: > Thanks for this code Hraban. I tried this last night and it worked > really well. I did have one stumbling block when I noticed that those > image files with a space in their names were not found, however > renaming without a space solved the problem. Is this a bug or a feature? The call to gm convert was lacking quoting of the file names. Fixed in attachment. While the code does some downsampling, the calculation is not always right, because it doesn’t consider scaling (or something like that). Hraban [-- Attachment #2: grph-downsample.lua --] [-- Type: text/plain, Size: 2779 bytes --] if not modules then modules = { } end modules ['grph-downsample'] = { version = 1.101, comment = "companion to grph-inc.mkiv", author = "Peter Münster", -- adapted to LMTX by Hraban copyright = "PRAGMA ADE / ConTeXt Development Team", license = "see context related readme files" } assert(not figures.getinfo2) figures.getinfo2 = function(name, page) -- [ [NTG-context] Pdf info with Lua/Ctx API ] if type(name) == "string" then name = { name = name, page = page } end if name.name then local data = figures.push(name) local info = figures.identify() if info.status.status ~= 0 then figures.check() -- !Counts pages here! end figures.pop() return --data info end end local format = string.format -- figures.cachepaths.path = "cache" -- should be setup-option local function sample_down(oldname, newname, resolution) print("DOWNSAMPLE sample_down " .. oldname .. " to " .. newname) local request = figures.current().request local width = request.width local height = request.height if resolution == "" then -- or (not width and not height) then print(format("DOWNSAMPLE Nothing to do: %s, %s, %s dpi, %s x %s px", oldname, newname, resolution, width, height)) return end local TEXpt = 65536 local inch = 72.27 -- MkIV: -- local image = img.scan{filename = oldname} -- LMTX: local image = figures.getinfo(oldname,1) image = image.status.private local xy = image.xsize / image.ysize if (not width and not height) then -- no size requested? use default width width = 300 * TEXpt end if not width then height = height / TEXpt width = height * xy end if not height then width = width / TEXpt height = width / xy end width = math.floor(width) height = math.floor(height) print(format("DOWNSAMPLE image size %dx%dpx. requested %dx%d?", image.xsize, image.ysize, width, height)) local xsize = math.floor(resolution * width / inch) local ysize = math.floor(resolution * height / inch) print(format("DOWNSAMPLE size %d x %d to %d x %d", image.xsize, image.ysize, xsize, ysize)) if xsize < image.xsize or ysize < image.ysize then local s = format("gm convert -resize %dx%d -resample %dx%d \"%s\" \"%s\"", xsize, ysize, resolution, resolution, oldname, newname) print("DOWNSAMPLE Conversion: " .. s) os.execute(s) else print(format("DOWNSAMPLE Nothing to do: %s, %s, %s dpi, %d x %d px", oldname, newname, resolution, width, height)) print(format("DOWNSAMPLE 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 [-- Attachment #3: Type: text/plain, Size: 496 bytes --] ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-09-02 9:26 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-09-01 8:44 setupexternalfigures and resoĺution juh+ntg-context--- via ntg-context 2022-09-01 8:51 ` Henning Hraban Ramm via ntg-context 2022-09-01 8:56 ` Henning Hraban Ramm via ntg-context 2022-09-01 10:37 ` juh+ntg-context--- via ntg-context 2022-09-01 13:05 ` Henning Hraban Ramm via ntg-context 2022-09-01 11:43 ` juh+ntg-context--- via ntg-context 2022-09-01 13:04 ` Henning Hraban Ramm via ntg-context 2022-09-01 17:22 ` juh+ntg-context--- via ntg-context 2022-09-02 8:39 ` Keith McKay via ntg-context 2022-09-02 9:26 ` Henning Hraban Ramm via ntg-context
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).