From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/87191 Path: news.gmane.org!not-for-mail From: Wolfgang Schuster Newsgroups: gmane.comp.tex.context Subject: Re: resize and center and clip image Date: Thu, 1 May 2014 21:31:15 +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 (Mac OS X Mail 7.2 \(1874\)) Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1398972700 15877 80.91.229.3 (1 May 2014 19:31:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 1 May 2014 19:31:40 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu May 01 21:31:35 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 1Wfwhi-0004zz-Mt for gctc-ntg-context-518@m.gmane.org; Thu, 01 May 2014 21:31:34 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 6E6961022E for ; Thu, 1 May 2014 21:31:34 +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 db+cdfF66LTG for ; Thu, 1 May 2014 21:31:34 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id AE4691020F for ; Thu, 1 May 2014 21:31:30 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 47E3F101E8 for ; Thu, 1 May 2014 21:31:27 +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 gH5hvlnMyyts for ; Thu, 1 May 2014 21:31:25 +0200 (CEST) Original-Received: from filter1-til.mf.surf.net (filter1-til.mf.surf.net [194.171.167.217]) by balder.ntg.nl (Postfix) with ESMTP id CF0B7101E1 for ; Thu, 1 May 2014 21:31:25 +0200 (CEST) Original-Received: from mail-ee0-x236.google.com (mail-ee0-x236.google.com [IPv6:2a00:1450:4013:c00::236]) by filter1-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s41JVGND028999 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Thu, 1 May 2014 21:31:25 +0200 Original-Received: by mail-ee0-f54.google.com with SMTP id b57so598076eek.27 for ; Thu, 01 May 2014 12:31:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=rGUjYZMGfGFkmw6ExYpzd8JbFN6XakJ/XniXUUTKGUs=; b=e3kCwGOj/p2EuXV5eeRX1Sqx8fGa8mWJZf0ysq5Gz8Iepqs0jj6CBb+20+wYs9xzX6 P3raLxTUzWnbK5JKlaEKWzIClXzpHg3ZVS14bp7lugXCRPw+HkgbntSI7Cwnh84no89U VdFEYoharI6ftbfb+vq9VD1JN7vp6TgJaI2rGq1l9EeCVvX7A7rWCIacrfy3MxnF3XuW y7zMrWk3HL3NID0NdANsbdEYQlHTT/vdnQIZKfTbbFgxOSy5DIijLJa13hXAis/3zVoC uP4HBixYK3cqN+fu9A/6PSDwmrX8txdkyDvsOJZBuB6NOk9YXUZfbAlCwo1cGP/usY7M RvDw== X-Received: by 10.14.7.137 with SMTP id 9mr3716769eep.114.1398972676491; Thu, 01 May 2014 12:31:16 -0700 (PDT) Original-Received: from keima.localdomain (x2f2423f.dyn.telefonica.de. [2.242.66.63]) by mx.google.com with ESMTPSA id q41sm78563783eez.7.2014.05.01.12.31.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 12:31:14 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.1874) X-Bayes-Prob: 0.0001 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=2a00:1450:4013:c00::236; country=IE X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0RLUHvgDj - c5b5dbf9be32 - 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:87191 Archived-At: Am 01.05.2014 um 20:00 schrieb Aditya Mahajan : > On Thu, 1 May 2014, Mikael P. Sundqvist wrote: >> \startluacode >> userdata =3D userdata or {} >> function userdata.lundklippfyllbild(str, bredd, hojd) >> if tex.dimen[0] / tex.dimen[2] < tex.dimen[4] / tex.dimen[6] then >> local skalning =3D >> -0.5*(tex.dimen[4]/tex.dimen[0]*tex.dimen[2]-tex.dimen[6]) >> context("\\vskip%ssp", skalning) >> context.externalfigure({str},{width=3Dbredd}) >> context.sprint("foo") >> else >> local skalning =3D >> -0.5*(tex.dimen[6]/tex.dimen[2]*tex.dimen[0]-tex.dimen[4]) >> context("\\hskip%ssp", skalning) >> context.externalfigure({str},{height=3Dhojd}) >> context.sprint("bar") >> end >> end >> \stopluacode >> = >> \unexpanded\def\lundklippfyllbild#1#2#3{% >> \startexternalfigurecollection[#1]% >> \useexternalfigure[#1][#1]% >> \stopexternalfigurecollection% >> \clip[ >> width=3D#2, >> height=3D#3, >> hoffset=3D0mm, >> voffset=3D0mm, >> ]{% >> \framed[width=3D#2,height=3D#3,align=3D{middle,lohi},offset=3Doverlay,fr= ame=3Doff]{% >> \dimen0=3D\externalfigurecollectionminwidth{#1}% >> \dimen2=3D\externalfigurecollectionmaxheight{#1}% >> \dimen4=3D#2% >> \dimen6=3D#3% >> {\ctxlua{userdata.lundklippfyllbild([=3D=3D[#1]=3D=3D],[=3D=3D[#2]=3D=3D= ],[=3D=3D[#3]=3D=3D])}}}}} >> = >> = >> = >> 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=3D\textwidth, > height=3D\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_requeste= d_wd < > \dimexpr\d_scaleandclip_actual_ht*100/\d_scaleandclip_requeste= d_ht \relax > \setbox\scaleandclip_box\hbox > {\scale[\c!width=3D\d_scaleandclip_requested_wd]{\box\next= box}}% > \scratchdimen=3D\the\dimexpr(\ht\scaleandclip_box - \d_scalean= dclip_requested_ht)/2\relax > \clip > [ > \c!voffset=3D\scratchdimen, > \c!height=3D\d_scaleandclip_requested_ht, > ]{\box\scaleandclip_box}% > \else > \setbox\scaleandclip_box\hbox > {\scale[\c!height=3D\d_scaleandclip_requested_ht]{\box\nex= tbox}}% > \scratchdimen=3D\the\dimexpr(\wd\scaleandclip_box - \d_scalean= dclip_requested_wd)/2\relax > \clip > [ > \c!hoffset=3D\scratchdimen, > \c!width=3D\d_scaleandclip_requested_wd, > ]{\box\scaleandclip_box}% > \fi > \egroup} > = > \protect > = > The usage is: > = > \scaleandclip[width=3D..., height=3D...]{ ... any box ...} > = > simimlar to the usage of \scale macro. We should convince Hans to add this functionality to the \scale macro with = =93factor=3Dclip=94. Wolfgang ___________________________________________________________________________= ________ If your question is of interest to others as well, please add an entry to t= he Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-cont= ext webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________= ________