Hello all, I have to place a number of images into some given-size frames in a layer. The images should be scaled proportionally to fit into the frame. The code I'm working with is: \defineframed[framedimg][ frame=on,framecolor=elux, background=color, backgroundcolor=white, width=\wdfig, height=\htfigone, offset=overlay, ] \setlayer[figs][voffset=\nextfigvoff]{% \framedimg{% \externalfigure[#1][ factor=fit, % maxwidth=\wdfig, % maxheight=\htfigone, % frame=on, ]% }% }% where \wdfig, \htfigone are the frame size and \nextfigvoff is the vertical offset which must be placed. I've tried factor=fit, factor=max, but in both cases I get images which cross the boundaries of the frame, mostly in the horizontal direction. If I add the maxwidth/maxheight specification, images don't get scaled at all. I would expect factor=fit to scale the image in such a way that the biggest direction fits into the enclosing box, while factor=max would scale the image in such a way that the smallest direction fits into the enclosing box. Instead, in both cases the vertical direction is being fitted, with no apparent consideration for the horizontal direction. What am I doing wrong and what should I do to fix it? -- Giuseppe "Oblomov" Bilotta
Friday, July 20, 2007 Giuseppe Bilotta wrote:
Hello all,
I have to place a number of images into some given-size frames in a layer. The images should be scaled proportionally to fit into the frame. The code I'm working with is:
\defineframed[framedimg][ frame=on,framecolor=elux, background=color, backgroundcolor=white, width=\wdfig, height=\htfigone, offset=overlay, ]
\setlayer[figs][voffset=\nextfigvoff]{% \framedimg{% \externalfigure[#1][ factor=fit, % maxwidth=\wdfig, % maxheight=\htfigone, % frame=on, ]% }% }%
where \wdfig, \htfigone are the frame size and \nextfigvoff is the vertical offset which must be placed. I've tried factor=fit, factor=max, but in both cases I get images which cross the boundaries of the frame, mostly in the horizontal direction. If I add the maxwidth/maxheight specification, images don't get scaled at all.
I would expect factor=fit to scale the image in such a way that the biggest direction fits into the enclosing box, while factor=max would scale the image in such a way that the smallest direction fits into the enclosing box. Instead, in both cases the vertical direction is being fitted, with no apparent consideration for the horizontal direction.
What am I doing wrong and what should I do to fix it?
Ok, I've tried studying the source and I really think that the way factor scaling is computed is wrong. However, the fix is nontrivial, and a somewhat thorough checking should be implemented, with earlier check for the factor value (fit, max, broad), since the logic selecting which dimension to scale depends on the kind of scaling. Anyway, I've found a temporary solutin to my problem by using a very large value of scale=, coupled with appropriate maxwidth and maxheight values. -- Giuseppe "Oblomov" Bilotta
Hi, What version of ConTeXt are you using? I just noticed a difference a few days ago between the version installed by TeXLive 2007 and the April 2007 release (tested locally & through contextgarden) placing an image into a natural table, using factor=max. I'll post an example in a separate thread shortly. Regards, Brian On Jul 20, 2007, at 7:05 AM, Giuseppe Bilotta wrote:
Friday, July 20, 2007 Giuseppe Bilotta wrote:
Hello all,
I have to place a number of images into some given-size frames in a layer. The images should be scaled proportionally to fit into the frame. The code I'm working with is:
\defineframed[framedimg][ frame=on,framecolor=elux, background=color, backgroundcolor=white, width=\wdfig, height=\htfigone, offset=overlay, ]
\setlayer[figs][voffset=\nextfigvoff]{% \framedimg{% \externalfigure[#1][ factor=fit, % maxwidth=\wdfig, % maxheight=\htfigone, % frame=on, ]% }% }%
where \wdfig, \htfigone are the frame size and \nextfigvoff is the vertical offset which must be placed. I've tried factor=fit, factor=max, but in both cases I get images which cross the boundaries of the frame, mostly in the horizontal direction. If I add the maxwidth/maxheight specification, images don't get scaled at all.
I would expect factor=fit to scale the image in such a way that the biggest direction fits into the enclosing box, while factor=max would scale the image in such a way that the smallest direction fits into the enclosing box. Instead, in both cases the vertical direction is being fitted, with no apparent consideration for the horizontal direction.
What am I doing wrong and what should I do to fix it?
Ok, I've tried studying the source and I really think that the way factor scaling is computed is wrong. However, the fix is nontrivial, and a somewhat thorough checking should be implemented, with earlier check for the factor value (fit, max, broad), since the logic selecting which dimension to scale depends on the kind of scaling.
Anyway, I've found a temporary solutin to my problem by using a very large value of scale=, coupled with appropriate maxwidth and maxheight values.
-- Giuseppe "Oblomov" Bilotta
______________________________________________________________________ _____________ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ______________________________________________________________________ _____________
Saturday, July 21, 2007 Brian R. Landy wrote:
Hi,
What version of ConTeXt are you using? I just noticed a difference a few days ago between the version installed by TeXLive 2007 and the April 2007 release (tested locally & through contextgarden) placing an image into a natural table, using factor=max. I'll post an example in a separate thread shortly.
According to the log: ConTeXt ver: 2007.04.17 12:51 MKII fmt: 2007.7.17 int: english/english It's the one shipped with Debian. -- Giuseppe "Oblomov" Bilotta
Giuseppe Bilotta wrote:
Friday, July 20, 2007 Giuseppe Bilotta wrote:
Hello all,
I have to place a number of images into some given-size frames in a layer. The images should be scaled proportionally to fit into the frame. The code I'm working with is:
\defineframed[framedimg][ frame=on,framecolor=elux, background=color, backgroundcolor=white, width=\wdfig, height=\htfigone, offset=overlay, ]
\setlayer[figs][voffset=\nextfigvoff]{% \framedimg{% \externalfigure[#1][ factor=fit, % maxwidth=\wdfig, % maxheight=\htfigone, % frame=on, ]% }% }%
where \wdfig, \htfigone are the frame size and \nextfigvoff is the vertical offset which must be placed. I've tried factor=fit, factor=max, but in both cases I get images which cross the boundaries of the frame, mostly in the horizontal direction. If I add the maxwidth/maxheight specification, images don't get scaled at all.
I would expect factor=fit to scale the image in such a way that the biggest direction fits into the enclosing box, while factor=max would scale the image in such a way that the smallest direction fits into the enclosing box. Instead, in both cases the vertical direction is being fitted, with no apparent consideration for the horizontal direction.
What am I doing wrong and what should I do to fix it?
Ok, I've tried studying the source and I really think that the way factor scaling is computed is wrong. However, the fix is nontrivial, and a somewhat thorough checking should be implemented, with earlier check for the factor value (fit, max, broad), since the logic selecting which dimension to scale depends on the kind of scaling.
the fit assumes operating on a page not in a box; an alternative is: \framed[width=5cm,height4cm] {\externalfigure[mill.png][maxwidth=4cm,maxheight=5cm,width=10cm]} i.e. setting the maximum values
Anyway, I've found a temporary solutin to my problem by using a very large value of scale=, coupled with appropriate maxwidth and maxheight values.
-- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
the fit assumes operating on a page not in a box; an alternative is:
\framed[width=5cm,height4cm] {\externalfigure[mill.png][maxwidth=4cm,maxheight=5cm,width=10cm]}
i.e. setting the maximum values
hmm, \frame can be slow. Maybe something like \vbox to4cm{\hsize=5cm ..} ? -- luigi ---------------------------------------------------------------- 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net
Monday, July 23, 2007 luigi scarso wrote:
the fit assumes operating on a page not in a box; an alternative is:
\framed[width=5cm,height4cm]
{\externalfigure[mill.png][maxwidth=4cm,maxheight=5cm,width=10cm]}
i.e. setting the maximum values
hmm, \frame can be slow. Maybe something like \vbox to4cm{\hsize=5cm ..} ?
Well, I'm already in a frame so it's not a problem. -- Giuseppe "Oblomov" Bilotta
Sunday, July 22, 2007 Hans Hagen wrote:
the fit assumes operating on a page not in a box;
Ah, didn't know that. I couldn't even tell from the sources, since it uses enclosing box dimensions and not page or paper sizes. I suspect the logic is broken at the page level too though, let me explain why. Currently, if I understand the code correctly, factor=fit expands the figure to have its major direction fit, while factor=max expands the figure to have its minor direction fit. Instead, the behavior I would expect from fit (resp. max) is for the *expansion ratio* to be the minimum (resp. maximum) of the expansion ratios in the two directions (not the sizes in those directions, but the ratio between the sizes of the figure and the container). The difference is noticeable when the container and contained have different aspect ratios. Consider for example a 20x30mm figure in a 50x150mm page (strange numbers, just used to show what I mean): with the current code, using 'fit' would consider the largest dimension (30) and thus calculate a factor of 150/30 = 5, but this gives us an image which is 100x150mm, i.e. an image that doesn't fit! Whereas, if we computed the ratios 50/20 = 2.5 and 150/30 = 5, we would know that the ratio to be picked was 2.5 in 'fit' and 5 in 'max'. Or I misintepreting the meaning of 'fit' and 'max'?
an alternative is:
\framed[width=5cm,height4cm]
{\externalfigure[mill.png][maxwidth=4cm,maxheight=5cm,width=10cm]}
i.e. setting the maximum values
I hadn't thought about using width and maxwidth (and maxheight) at the same time, thanks. Of course, I'd rather have 'fit' and 'max' usable in boxes :) -- Giuseppe "Oblomov" Bilotta
Giuseppe Bilotta wrote:
I hadn't thought about using width and maxwidth (and maxheight) at the same time, thanks. Of course, I'd rather have 'fit' and 'max' usable in boxes :)
sure, i'll redo that part anyway, since in luatex we can calculate in lua instead of tex which is more convenient (less code too) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (4)
-
Brian R. Landy
-
Giuseppe Bilotta
-
Hans Hagen
-
luigi scarso