From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/77678 Path: news.gmane.org!not-for-mail From: =?utf-8?Q?Peter_M=C3=BCnster?= Newsgroups: gmane.comp.tex.context Subject: Re: t-degrade.tex (solved) Date: Wed, 01 Aug 2012 00:36:45 +0200 Message-ID: <87obmvv9qa.fsf@micropit.couberia.bzh> References: <877gtpv5lk.fsf@micropit.couberia.bzh> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1343774224 15932 80.91.229.3 (31 Jul 2012 22:37:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 31 Jul 2012 22:37:04 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Wed Aug 01 00:37:04 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SwL3m-0006N2-U9 for gctc-ntg-context-518@m.gmane.org; Wed, 01 Aug 2012 00:37:03 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id A0DCE1020A; Wed, 1 Aug 2012 00:37:01 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id RrKAfpfTWLjL; Wed, 1 Aug 2012 00:36:58 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 58C5E10200; Wed, 1 Aug 2012 00:36:58 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 6464310200 for ; Wed, 1 Aug 2012 00:36:56 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Rkp2jlk5u8+8 for ; Wed, 1 Aug 2012 00:36:48 +0200 (CEST) Original-Received: from filter3-utr.mf.surf.net (filter3-utr.mf.surf.net [195.169.124.154]) by balder.ntg.nl (Postfix) with ESMTP id 1D368101FF for ; Wed, 1 Aug 2012 00:36:48 +0200 (CEST) Original-Received: from smtp.smtpout.orange.fr (smtp07.smtpout.orange.fr [80.12.242.129]) by filter3-utr.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q6VMakNk019765 for ; Wed, 1 Aug 2012 00:36:46 +0200 Original-Received: from micropit.couberia.bzh ([2.14.208.194]) by mwinf5d13 with ME id hAcl1j0074CBZ2y03Acllm; Wed, 01 Aug 2012 00:36:46 +0200 Original-Received: by micropit.couberia.bzh (Postfix, from userid 1000) id 950D15007EF; Wed, 1 Aug 2012 00:36:45 +0200 (CEST) Mail-Followup-To: mailing list for ConTeXt users In-Reply-To: <877gtpv5lk.fsf@micropit.couberia.bzh> ("Peter =?utf-8?Q?M?= =?utf-8?Q?=C3=BCnster=22's?= message of "Fri, 27 Jul 2012 12:52:23 +0200") User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1 (gnu/linux) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=80.12.242.129; country=FR; latitude=46.0000; longitude=2.0000; http://maps.google.com/maps?q=46.0000,2.0000&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 08HFaAK2J - 91a4ac754b9d - 20120801 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 195.169.124.154 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:77678 Archived-At: --=-=-= Content-Type: text/plain Now I can downsample jpeg-files on the fly, see attached example file. But I need 2 patches: 1.) To get the width and the height into the name of the file, because when the figure dimensions change, there must be a new conversion: --8<---------------cut here---------------start------------->8--- --- grph-inc.lua~ 2012-06-05 10:37:01.000000000 +0200 +++ grph-inc.lua 2012-07-31 22:40:39.214426838 +0200 @@ -528,6 +528,9 @@ if resolution and resolution ~= "" then -- the order might change newbase = newbase .. "_" .. resolution end + local width = figures.current().request.width + local height = figures.current().request.height + newbase = newbase .. "_" .. width .. "_" .. height -- -- see *, we had: -- --8<---------------cut here---------------end--------------->8--- 2.) To avoid crap in the width and height options: --8<---------------cut here---------------start------------->8--- --- grph-inc.mkiv~ 2012-07-20 23:26:52.000000000 +0200 +++ grph-inc.mkiv 2012-08-01 00:02:23.851094854 +0200 @@ -293,6 +293,10 @@ % \the\t_grph_include_local_settings \dostarttagged\t!image\empty + \edef\current_width{\externalfigureparameter\c!width}% + \edef\current_height{\externalfigureparameter\c!height}% + \def\nocrap##1{\doifnotemptyvalue{##1}{% + \the\dimexpr\csname##1\endcsname\relax}}% \ctxlua{figures.push { name = "\p_grph_include_name", label = "\p_grph_include_label", @@ -312,8 +316,8 @@ resolution = "\externalfigureparameter\c!resolution", color = "\internalspotcolorparent{\externalfigureparameter\c!color}", % hack is needed ["repeat"] = "\externalfigureparameter\c!repeat", - width = "\externalfigureparameter\c!width", % can be crap - height = "\externalfigureparameter\c!height", % can be crap + width = "\nocrap{current_width}", % no more crap + height = "\nocrap{current_height}", % no more crap } }% \ctxlua{figures.identify()}% % also mode: checkpresense only --8<---------------cut here---------------end--------------->8--- Hans, could you please patch the files? Cheers, -- Peter --=-=-= Content-Type: text/x-tex Content-Disposition: inline; filename=downsample.tex \startluacode 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:sub(1, -3) local height = request.height:sub(1, -3) if resolution == "" or (width == "" and 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 width == "" then width = height * xy end if height == "" then height = width / xy 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 -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 figures.converters.jpg = figures.converters.jpg or {} figures.converters.jpg["lowres.jpg"] = sample_down \stopluacode \starttext \setupexternalfigures[resolution=50, conversion=lowres.jpg] \externalfigure[hacker][width=0.5\textwidth] \setupexternalfigures[resolution=10] \externalfigure[hacker][width=0.5\textwidth] \stoptext --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --=-=-=--