From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/87190 Path: news.gmane.org!not-for-mail From: "Mikael P. Sundqvist" Newsgroups: gmane.comp.tex.context Subject: Re: resize and center and clip image Date: Thu, 1 May 2014 21:27:26 +0200 Message-ID: References: <7BE13927-B54E-4FC6-8C9E-2669D51CC6F2@gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1398972471 12013 80.91.229.3 (1 May 2014 19:27:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 1 May 2014 19:27:51 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu May 01 21:27:47 2014 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([5.39.185.229]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Wfwe2-0000Kn-RF for gctc-ntg-context-518@m.gmane.org; Thu, 01 May 2014 21:27:46 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 4C0FE10274 for ; Thu, 1 May 2014 21:27:46 +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 54zBQ4osh1xU for ; Thu, 1 May 2014 21:27:46 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 1C13710206 for ; Thu, 1 May 2014 21:27:42 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id CA0C8101E8 for ; Thu, 1 May 2014 21:27:37 +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 CDq+4aqgQZ7Z for ; Thu, 1 May 2014 21:27:36 +0200 (CEST) Original-Received: from filter1-utr.mf.surf.net (filter1-utr.mf.surf.net [195.169.124.152]) by balder.ntg.nl (Postfix) with ESMTP id 3D132101E1 for ; Thu, 1 May 2014 21:27:27 +0200 (CEST) Original-Received: from mail-wg0-x233.google.com (mail-wg0-x233.google.com [IPv6:2a00:1450:400c:c00::233]) by filter1-utr.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s41JRPs4022086 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Thu, 1 May 2014 21:27:25 +0200 Original-Received: by mail-wg0-f51.google.com with SMTP id z12so2691214wgg.10 for ; Thu, 01 May 2014 12:27:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ydIE2H0bxHcVmBQk2ShIKbhnncCJb6NahVW/0L4CbQ0=; b=kQ5B21G1W+e9KUWgwe75RL16Z9spBVkbJ7+BbJGieXVxXZt4XpeSYVyWG3UUXTVxAY uBDt2bSC/BFTeRBXqtCzzsDrDiJYo25JVGPd5avCe44q8Fc3nVjoR2ueP0vNhHzdpj54 BWVclGP1RkUI3bFWO6mtIS2p80OcJFTMPK2eJWHhNSbPxzGc7rFm5gkdK5wO84Sxpgdq 4CIBvvA/A/nKEI7qWbKUof9gzvM6lLhWLLnFUWpsfL/DHC0NOj5/pQjA2FNJ5gRpL3TB EwTtK0nKN5/GHIbo2CVUpX3kjPAhz4OWakgT+XEwGU424V662ry6iTxAfnI7Yyk4zWq6 Aujw== X-Received: by 10.180.74.203 with SMTP id w11mr3368042wiv.27.1398972446270; Thu, 01 May 2014 12:27:26 -0700 (PDT) Original-Received: by 10.180.93.72 with HTTP; Thu, 1 May 2014 12:27:26 -0700 (PDT) In-Reply-To: X-Bayes-Prob: 0.0001 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=2a00:1450:400c:c00::233; country=IE X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 07LUHrpe8 - 6d8d4db15d6b - 20140501 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) 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:87190 Archived-At: On Thu, May 1, 2014 at 8:00 PM, Aditya Mahajan wrote: > On Thu, 1 May 2014, Mikael P. Sundqvist wrote: >> >> \startluacode >> userdata = userdata or {} >> function userdata.lundklippfyllbild(str, bredd, hojd) >> if tex.dimen[0] / tex.dimen[2] < tex.dimen[4] / tex.dimen[6] then >> local skalning = >> -0.5*(tex.dimen[4]/tex.dimen[0]*tex.dimen[2]-tex.dimen[6]) >> context("\\vskip%ssp", skalning) >> context.externalfigure({str},{width=bredd}) >> context.sprint("foo") >> else >> local skalning = >> -0.5*(tex.dimen[6]/tex.dimen[2]*tex.dimen[0]-tex.dimen[4]) >> context("\\hskip%ssp", skalning) >> context.externalfigure({str},{height=hojd}) >> context.sprint("bar") >> end >> end >> \stopluacode >> >> \unexpanded\def\lundklippfyllbild#1#2#3{% >> \startexternalfigurecollection[#1]% >> \useexternalfigure[#1][#1]% >> \stopexternalfigurecollection% >> \clip[ >> width=#2, >> height=#3, >> hoffset=0mm, >> voffset=0mm, >> ]{% >> \framed[width=#2,height=#3,align={middle,lohi},offset=overlay,frame=off]{% >> \dimen0=\externalfigurecollectionminwidth{#1}% >> \dimen2=\externalfigurecollectionmaxheight{#1}% >> \dimen4=#2% >> \dimen6=#3% >> {\ctxlua{userdata.lundklippfyllbild([==[#1]==],[==[#2]==],[==[#3]==])}}}}} >> >> >> >> and then run >> >> >> \lundklippfyllbild{k.jpg}{\textwidth}{\textheight} > > > Here is an eTeX solution. > > \unprotect > > \newdimen\d_scaleandclip_actual_wd > \newdimen\d_scaleandclip_actual_ht > > \newdimen\d_scaleandclip_requested_wd > \newdimen\d_scaleandclip_requested_ht > > \newbox\scaleandclip_box > > \installnamespace{scaleandclip} > \installcommandhandler \????scaleandclip {scaleandclip} \????scaleandclip > > \setupscaleandclip > [width=\textwidth, > height=\textheight] > > \unexpanded\def\scaleandclip{\dodoubleempty\doscaleandclip} > > \def\doscaleandclip[#1][#2]% > {\bgroup > \ifsecondargument > \edef\currentscaleandclip{#1}% > \setupcurrentscaleandclip[#2]% > \else\iffirstargument > \doifassignmentelse{#1} > {\let\currentscaleandclip\empty > \setupcurrentscaleandclip[#1]} > {\edef\currentscaleandclip{#1}} > \else > \let\currentscaleandclip\empty > \fi\fi > \dowithnextboxcs\scaleandclip_finish\hbox} > > \def\scaleandclip_finish > {% > \d_scaleandclip_requested_wd > \dimexpr\scaleandclipparameter\c!width\relax > \d_scaleandclip_requested_ht > \dimexpr\scaleandclipparameter\c!height\relax > % > \d_scaleandclip_actual_wd\wd\nextbox > \d_scaleandclip_actual_ht\dimexpr\ht\nextbox + \dp\nextbox\relax > % > > \ifdim\dimexpr\d_scaleandclip_actual_wd*100/\d_scaleandclip_requested_wd < > > \dimexpr\d_scaleandclip_actual_ht*100/\d_scaleandclip_requested_ht \relax > \setbox\scaleandclip_box\hbox > > {\scale[\c!width=\d_scaleandclip_requested_wd]{\box\nextbox}}% > \scratchdimen=\the\dimexpr(\ht\scaleandclip_box - > \d_scaleandclip_requested_ht)/2\relax > \clip > [ > \c!voffset=\scratchdimen, > \c!height=\d_scaleandclip_requested_ht, > ]{\box\scaleandclip_box}% > \else > \setbox\scaleandclip_box\hbox > > {\scale[\c!height=\d_scaleandclip_requested_ht]{\box\nextbox}}% > \scratchdimen=\the\dimexpr(\wd\scaleandclip_box - > \d_scaleandclip_requested_wd)/2\relax > \clip > [ > \c!hoffset=\scratchdimen, > \c!width=\d_scaleandclip_requested_wd, > ]{\box\scaleandclip_box}% > \fi > \egroup} > > \protect > > The usage is: > > \scaleandclip[width=..., height=...]{ ... any box ...} > > simimlar to the usage of \scale macro. > > > \starttext > > \dontleavehmode > \scaleandclip[width=3cm, > height=3cm]{\externalfigure[cow.pdf][width=3cm,frame=on]} > \scale[maxwidth=3cm, > maxheight=3cm]{\externalfigure[cow.pdf][width=3cm,frame=on]} > > \dontleavehmode > \scaleandclip[width=3cm, > height=3cm]{\externalfigure[cow.pdf][width=3cm,height=10cm,frame=on]} > \scale[maxwidth=3cm, > maxheight=3cm]{\externalfigure[cow.pdf][width=3cm,height=10cm,frame=on]} > > \dontleavehmode > \scaleandclip[width=3cm, > height=3cm]{\externalfigure[cow.pdf][width=10cm,height=3cm,frame=on]} > \scale[maxwidth=3cm, > maxheight=3cm]{\externalfigure[cow.pdf][width=10cm,height=3cm,frame=on]} > > \stoptext > > ___________________________________________________________________________________ > 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 > ___________________________________________________________________________________ Thanks Aditya! That is more general and looks more ConTeXt-ish to me with the options. I should study your code in detail to learn how that is done. Mikael ___________________________________________________________________________________ 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 ___________________________________________________________________________________