[xep-support] scale-when-image-is-too-big

Clay Leeds cleeds at medata.com
Tue Oct 15 07:59:15 PDT 2002


Matthias,

Thanks very much for this! You've saved me a couple of days work... If this 
XSL were danke-ware, I'd say "Danken Sie einem Bündel!" (isn't Babelfish 
super!?)...

You mention that:

>(Actually this is a simplified version because I support pictures inside
>tables as well).

BTW, how would the code be different when tables are involved? I too am 
placing my picture inside of a table, and I've noticed that (in FOP) the 
width/height & content-width/content-height don't seem to have any effect 
(it could be because I'm typically scaling down).

Also, I notice you use "document($dataFile)" but it doesn't appear to be 
defined in the XSL below. Do you replace "$dataFile" with what you use to 
call the XML file with the graphics?

Thanks again!

Web Maestro Clay

At 01:31 AM 10/15/2002, you wrote:
> > Do you have example code for passing the new image height & width values
>to
> > the XSL template? Are you using xsl:param & with-param coupled with
> > xsl:call-template?
>
>Yes, this is what I use. Here's some code:
>
>My xml data file has this format:
>
><?xml version="1.0" encoding="UTF-8"?>
><graphics>
>   <pic1.jpg>
>     <width>6.29</width>
>     <height>13.12</height>
>   </pic1.jpg>
>   <pic2.gif>
>     <width>17.76</width>
>     <height>2.16</height>
>   </pic2.gif>
></graphics>
>
>When I handle graphics, I call the template setScaling...
>
><fo:external-graphic alignment-baseline="middle">
>   <xsl:attribute name="src"><xsl:value-of select="$filename"
>/></xsl:attribute>
>   <xsl:call-template name="setScaling">
>     <xsl:with-param name="filename" select="$filename" />
>   </xsl:call-template>
></fo:external-graphic>
>
>...which looks like this:
>
><xsl:template name="setScaling">
>   <xsl:param name="filename" />
>   <xsl:variable name="imageWidth">
>     <xsl:value-of
>select="document($dataFile)//*[name()=$filename]/*[name()='width']" />
>   </xsl:variable>
>   <xsl:variable name="imageHeight">
>     <xsl:value-of
>select="document($dataFile)//*[name()=$filename]/*[name()='height']" />
>   </xsl:variable>
>   <xsl:variable name="xScale">
>     <xsl:choose>
>       <xsl:when test="number($imageWidth) > number($typeAreaWidth)">
>         <xsl:value-of select="100 * number($typeAreaWidth) div
>number($imageWidth)" />
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:value-of select="100" />
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:variable>
>   <xsl:variable name="yScale">
>     <xsl:choose>
>       <xsl:when test="number($imageHeight) > number($typeAreaHeight)">
>         <xsl:value-of select="100 * number($typeAreaHeight) div
>number($imageHeight)" />
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:value-of select="100" />
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:variable>
>   <xsl:variable name="scale">
>     <xsl:choose>
>       <xsl:when test="number($yScale) > number($xScale)">
>         <xsl:value-of select="$xScale" />
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:value-of select="$yScale" />
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:variable>
>   <xsl:attribute name="content-width"><xsl:value-of select="$scale"
>/>%</xsl:attribute>
>   <xsl:attribute name="content-height"><xsl:value-of select="$scale"
>/>%</xsl:attribute>
></xsl:template>
>
>(Actually this is a simplified version because I support pictures inside
>tables as well).
>
>
> > However, I would like to attract your and other users' attention to the
>fact
> > that acrobat (or any other pdf/ps interpreter) is usually a poor quality
> > performer when it comes to scaling raster images.
>
>For our needs, the image quality is sufficient.
>
>Regards,
>Matthias
>
>--
>Matthias Belz <Matthias.Belz at springer.de>
>Electronic Technologies, Springer-Verlag Heidelberg
>-------------------
>By using the Service, you expressly agree to these Terms of Service 
>http://www.renderx.com/tos.html

Clay Leeds
Web Developer/Programmer
cleeds at medata.com

-------------------
By using the Service, you expressly agree to these Terms of Service http://www.renderx.com/tos.html



More information about the Xep-support mailing list