xsl-list
[Top] [All Lists]

Re: [xsl] Image size with XSL?

2016-12-19 10:42:25
A nice way to choreograph all this, regardless of how you extract the image 
size, is with Xproc [1]. You can avoid writing the intermediate files to disk.

Regards,
--Paul

[1] http://www.w3.org/TR/xproc/


On Dec 19, 2016, at 10:08, Mark Wilson mark(_at_)knihtisk(_dot_)org 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Thanks, Max.
Problem solved. Yours proved to be the simplest for me to implement. If 
anyone needs to deal with image sizes in XSLT, here is how to generate an XML 
file with all the pertinent information.
Mark

For the archives:
I had a spot of trouble getting this solution to work and went off list. Max 
was kind enough to explain in a bit more detail how to solve my problem.

ImageMagick is a free download. During the download, I let it write itself 
into my Path on Windows 10.

From the directory where the images were stored, I executed the following 
from a Windows cmd prompt:

sizes.xml magick identify ^
  -format 
"<image>\n<file>%i</file>\n<width>%w</width>\n<height>%h</height>\n</image>" ^
  *.jpg

(Command line split for display here with '^', Windows style)

The tricky part, as Max explained, was that the redirection comes at the 
beginning, not at the end, of the prompt. The file 'sizes.xml' required 
opening and closing elements be added to be well-formed, but provided this 
output:

<List>
  <image>
      <file>2921-DV88-2.jpg</file>
      <width>640</width>
      <height>480</height>
  </image>
  <image>
      <file>2921-mn1.jpg</file>
      <width>640</width>
      <height>480</height>
  </image>
.......
</List>


On 12/19/2016 4:16 AM, Max Zhaloba mzhaloba(_at_)intelliarts(_dot_)com wrote:
At first I was under impression that we were calling identify.exe once per 
each image, but actually it works even simpler - identifier can receive a 
file pattern with a wildcard such as "*.jpg *.png *.tif " and iterate over 
files itself.

Glad that it works for you!

- Max

On 18.12.2016 11:18 PM, Mark Wilson pubs(_at_)knihtisk(_dot_)org wrote:
Hi Max,
I saw that application but did not realize that it could be used the way 
you suggested (in a batch mode).
I now have two solutions to explore, yours and John's binary module. Should 
keep me off the streets for a few days.
Thanks everyone. Very, very helpful.
Regards,
Mark

On 12/18/2016 2:07 PM, Max Zhaloba mzhaloba(_at_)intelliarts(_dot_)com 
wrote:
We had a similar task on one of our projects. However there was not so 
many files, we also invoked an external utility to read the metadata. We 
used Image Magick (imagemagick.org).

You can iterate over image files and call identify.exe with "-format" 
option that contains XML tags:
<image>\n<file>%i</file>\n<width>%w</width>\n<height>%h</height>\n</image>
and redirect the standard output to file. Then as soon as you wrap the 
contents of that file into the pair of opening/closing tags it becomes a 
well-formed XML an you can read it from XSLT.  And since performance is a 
factor for you, it will be faster to use <xsl:key> for that purpose.

There's a handy installer of Image Magick for OS X at 
http://cactuslab.com/imagemagick, if you're on Mac.

- Max
(blog.xml.rocks <http://blog.xml.rocks>)

On 18.12.2016 9:54 PM, Mark Wilson mark(_at_)knihtisk(_dot_)org wrote:
I have an XSL stylesheet driven by an XML data source that produces about 
5000 different pages, many with multiple images. I have been adding by 
hand a placement-index to the XML data source that arranges the images 
neatly, as with this page:
http://www.cpslib.org/amp/europa-themes.htm.

I am now faced with adding a huge number of images to a page or pages 
like this:
http://www.cpslib.org/flaws/flaws.htm

I would like to add the placement-index to the XML data source 
programmatically. Is there a way to obtain the height or width of a jpeg 
image from the file itself (image.jpg, for instance) using XSLT? Or, can 
someone suggest another way to do this programmatically?

Feel free to wander around the website if you find it interesting.

Thanks,
Mark

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/2754769> (by email)

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/2950507> (by email)


XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/2966980> (by email <>)

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>