From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/87183 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 15:38:29 +0200 Message-ID: References: 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 1398951536 3833 80.91.229.3 (1 May 2014 13:38:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 1 May 2014 13:38:56 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu May 01 15:38:52 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 1WfrCL-0006Im-0F for gctc-ntg-context-518@m.gmane.org; Thu, 01 May 2014 15:38:49 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id AA3C41026A for ; Thu, 1 May 2014 15:38:48 +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 BhS1mbL+12AV for ; Thu, 1 May 2014 15:38:48 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id E92571020F for ; Thu, 1 May 2014 15:38:44 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id B4775101E9 for ; Thu, 1 May 2014 15:38:40 +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 M8mosT3JumRb for ; Thu, 1 May 2014 15:38:39 +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 34584101E1 for ; Thu, 1 May 2014 15:38:39 +0200 (CEST) Original-Received: from mail-wi0-x22e.google.com (mail-wi0-x22e.google.com [IPv6:2a00:1450:400c:c05::22e]) by filter1-utr.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s41DcTnj022031 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Thu, 1 May 2014 15:38:38 +0200 Original-Received: by mail-wi0-f174.google.com with SMTP id d1so717233wiv.13 for ; Thu, 01 May 2014 06:38:29 -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=woh97lPvoxgq+Dxb5hVCTCf0hFVUlCmfox1yt2nieaA=; b=q7lB9fiQU83IYXRu/bQZ82Reoe18tEUlTocsKE2QUtFNFLVFh60WzvWYEAVtS4EqZM xx4Y+m4Fsq6qrRwGvqwz8R2R7vl2+Hl5IbBB0TqlQximtVWSEVTUgY5r/y3IOAfa4egR j4LQlxVurLav2TwnzdtBbITY9DECouBXA94usRDO/jIzmuZ991Ijdve8cui+uQ9A/TDK IuToM44cZMpHQVdRT6wJaf5NagTWygssAYca47NUnPZlfmR+iAjhFaj1Wj1wyL2fkHxv ShOhZ7SCrZ7pZey0Y2A/pAvM26+UnLL7FX6ptcUyxgrpuJs4JpQ0GSnH69OYmzPUlN8S XemQ== X-Received: by 10.194.78.77 with SMTP id z13mr997769wjw.64.1398951509809; Thu, 01 May 2014 06:38:29 -0700 (PDT) Original-Received: by 10.180.93.72 with HTTP; Thu, 1 May 2014 06:38:29 -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:c05::22e; country=IE X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 07LUBCtPj - 8728450cce97 - 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:87183 Archived-At: 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=8cm,height=7cm]{% \framed[width=8cm,height=7cm,align={middle,lohi},offset=overlay]{% \dimen0=\externalfigurecollectionminwidth{k.jpg} \dimen2=\externalfigurecollectionmaxheight{k.jpg} \dimen4=8cm \dimen6=7cm \startluacode 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({"k.jpg"},{width="8cm"}) 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({"k.jpg"},{height="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 ___________________________________________________________________________________