From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/87186 Path: news.gmane.org!not-for-mail From: Otared Kavian Newsgroups: gmane.comp.tex.context Subject: Re: resize and center and clip image Date: Thu, 1 May 2014 18:43:36 +0200 Message-ID: <0CC7AD92-0342-4501-98C8-B7E0196322E1@gmail.com> 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="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1398962647 14581 80.91.229.3 (1 May 2014 16:44:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 1 May 2014 16:44:07 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu May 01 18:44:02 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 1Wfu5Y-00035y-RK for gctc-ntg-context-518@m.gmane.org; Thu, 01 May 2014 18:44:00 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 3F4821026D for ; Thu, 1 May 2014 18:44:00 +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 8vRLsfdBa+kY for ; Thu, 1 May 2014 18:44:00 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id F3D7C10258 for ; Thu, 1 May 2014 18:43:54 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 0F980101E8 for ; Thu, 1 May 2014 18:43:52 +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 y3zfH-QUTHT4 for ; Thu, 1 May 2014 18:43:50 +0200 (CEST) Original-Received: from filter2-til.mf.surf.net (filter2-til.mf.surf.net [194.171.167.218]) by balder.ntg.nl (Postfix) with ESMTP id 7E1D7101E1 for ; Thu, 1 May 2014 18:43:42 +0200 (CEST) Original-Received: from mail-we0-x22e.google.com (mail-we0-x22e.google.com [IPv6:2a00:1450:400c:c03::22e]) by filter2-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s41Ghf71006439 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Thu, 1 May 2014 18:43:41 +0200 Original-Received: by mail-we0-f174.google.com with SMTP id k48so3380201wev.19 for ; Thu, 01 May 2014 09:43:41 -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=inmIjQamqd+Gzh0pM12l5J0wRrVmb2NwJzqMAZyDrXA=; b=vHpoMwckiE5sqd1HHBPmF5rctjutn5S2ULwVa272VfO8TgHPOEdnw/VZHrUVGqts/v YwrjWbK+x8X4YV5C/pUVGtvXNmFNhb852SZYJ3ruxpcUv63nAoWKjuHW+twvn5iksxz2 16LiykfwRD4kOyy6riPshLOnT45r2eIxo0CcDm6NQJV1zZL7423u/mw9zmpJTieNCTEL glHd6TOcljvors6W+LBkP6t5BKww88Ow15ZD0DzJyFEzCL5U0r6SQA1JpH7gL7Qizaar wP1ih9kdNBzLYBs4jx6QznGO4gjK1h4BRk0djEY3YcYAXRA6HnRxELkR0PtpsGW+8KsA 3NRg== X-Received: by 10.194.71.164 with SMTP id w4mr9910956wju.0.1398962621087; Thu, 01 May 2014 09:43:41 -0700 (PDT) Original-Received: from [192.168.0.100] (lns-bzn-35-82-250-199-2.adsl.proxad.net. [82.250.199.2]) by mx.google.com with ESMTPSA id ej7sm4725293wib.9.2014.05.01.09.43.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 09:43:40 -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:400c:c03::22e; country=IE X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0TLUEHFbP - 6f2eec626e11 - 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:87186 Archived-At: Hi Mikael, With your new definitions and lua code I could typeset and test a few examp= les: it is very nice, thanks for sharing! Best regards: OK On 1 mai 2014, at 17:07, Mikael P. Sundqvist wrote: > Interesting, > = > I use ConTeXt ver: 2014.04.28 23:24 MKIV beta fmt: 2014.4.29 int: > english/english > = > and it works. I now defined this with argument: > = > \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,fra= me=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} > = > = > it works well. Of course you should replace k.jpg with some other image n= ame... > = > /Mikael > = > PS And please, if someone has opinions about the code, don't hesitate > to tell me. This is my first time using lua... > = > = > On Thu, May 1, 2014 at 4:59 PM, Otared Kavian wrote: >> Hi Mikael, >> = >> Out of curiosity I tried to typeset your example (after adding the usual= \starttext, \stoptext), but using >> ConTeXt ver: 2014.04.28 23:24 MKIV beta fmt: 2014.4.29 int: en= glish/english >> I obtained a TeX error: >> = >> tex error > error on line 13 in file /Users/kavian/Context/essais/= mkii/figures/resize-and-center.tex: ! Undefined control sequence >> = >> = >> \startexternalfigurecollection ...igurecollection >> {#1}\settrue \c_grph_in= clu... >> l.13 \clip[width=3D8cm,height=3D7cm] >> {% >> = >> 3 \startexternalfigurecollection[k.jpg] >> 4 \useexternalfigure[k.jpg][k.jpg] >> 5 \stopexternalfigurecollection >> = >> I did not understand what is the =AB Undefined control sequence =BB, sin= ce I think \clip is a known control sequence. >> = >> Best regards: OK >> = >> On 1 mai 2014, at 15:38, Mikael P. Sundqvist wrote: >> = >>> OK, sorry for the noise. I think I have the solution: >>> = >>> \startexternalfigurecollection[k.jpg] >>> \useexternalfigure[k.jpg][k.jpg] >>> \stopexternalfigurecollection >>> = >>> = >>> \externalfigurecollectionminwidth{k.jpg} >>> \externalfigurecollectionmaxheight{k.jpg} >>> = >>> \clip[width=3D8cm,height=3D7cm]{% >>> \framed[width=3D8cm,height=3D7cm,align=3D{middle,lohi},offset=3Doverlay= ]{% >>> \dimen0=3D\externalfigurecollectionminwidth{k.jpg} >>> \dimen2=3D\externalfigurecollectionmaxheight{k.jpg} >>> \dimen4=3D8cm >>> \dimen6=3D7cm >>> \startluacode >>> 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({"k.jpg"},{width=3D"8cm"}) >>> 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({"k.jpg"},{height=3D"7cm"}) >>> context.sprint("bar") >>> end >>> \stopluacode >>> }} >>> = >>> If there are any bad side effects of this or simplifications, please >>> do not hesitate to tell me :) >>> = >>> /Mikael >>> = >>> On Thu, May 1, 2014 at 1:50 PM, Mikael P. Sundqvist = wrote: >>>> Hi! >>>> = >>>> Assume that I want to fill in the text area with images, and I want to >>>> clip and scale them according to these rules: >>>> = >>>> 1) If the image is "too wide" (in sense of proportions), then scale it >>>> so that the height fits the text area height, center it, and clip it >>>> to the text area. (See the attached image, on top, where the blue area >>>> is supposed to show the text area and the red rectangle the image.) >>>> = >>>> 2) If the image is "too high" (in sense of proportions), then scale it >>>> so that the width fits the text area width, center it, and clip it to >>>> the text area. (See the attached image, on bottom.) >>>> = >>>> The background why I want to do this is that I'm making a small >>>> template for presentations, and I'd like the users to insert images as >>>> background without really having to think about if their proportions >>>> fit or not. >>>> = >>>> Best regards, 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 >>> _______________________________________________________________________= ____________ >> = >> ________________________________________________________________________= ___________ >> If your question is of interest to others as well, please add an entry t= o the Wiki! >> = >> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-c= ontext >> webpage : http://www.pragma-ade.nl / http://tex.aanhet.net >> archive : http://foundry.supelec.fr/projects/contextrev/ >> wiki : http://contextgarden.net >> ________________________________________________________________________= ___________ > _________________________________________________________________________= __________ > 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-co= ntext > webpage : http://www.pragma-ade.nl / http://tex.aanhet.net > archive : http://foundry.supelec.fr/projects/contextrev/ > wiki : http://contextgarden.net > _________________________________________________________________________= __________ ___________________________________________________________________________= ________ 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 ___________________________________________________________________________= ________