Re: [NTG-context] Images in MultiMarkdown -> context -> PDF
Well, that lead to an interesting experiment. I used convert to -resample a set of images to 300dpi and redid the compile. They are all now too bod, many off the right side of the page. Then did the same but set to 72. They are still too big. Odd, from too small to too big. I will try and be a bit more precise and craft a text doc to play with this and report the results. Thanks for your help! Guy On 11/21/2012 10:51 AM, Sietse Brouwer wrote:
On Wed, Nov 21, 2012 at 3:55 PM, Guy Stalnaker
wrote: Thanks - see my first post for a link to a web folder where you can find the .tex file, the .pdf context produces, two screenshots of the differing image treatment and two of the image files shown in the screenshots.
Gah --- missed that. Thanks!
The resolution of the image is is either not correctly set, or not correctly read by ConTeXt --- so ConTeXt assumes 300dpi instead of 72. I've attached a self-made image of 547px wide, and run the following file:
\starttext \externalfigure[CMSLogin.jpg] \crlf \figurenaturalwidth\ -- \figurexresolution\ -- \figurexsize
\externalfigure[cross.jpg] \crlf \figurenaturalwidth\ -- \figurexresolution\ -- \figurexsize \stoptext
This prints the following dimensions for your figure and the Gimp-made one, respectively:
8635829sp – 0 – 547 35982623sp – 72 – 547
Can't remember how to convert scaled points to inches, so here's some fraction juggling instead. The naturalwidth of the cross is 4.2 times larger: 35982623 / 8635829 = 4.166667
So the login jpg will have 4.16666666 times as many dpi. 72 * 4.166667 = 300 dpi
Which corresponds to this observation by you:
But note that I attempted to test the dpi theory by selecting an image and using GIMP to set its dpi to 300 yet that resulted in no visible change.
What if you use the GIMP to set its dpi to 72?
--Sietse
-- "There is only love, and then oblivion. Love is all we have to set against hatred." (paraphrased) Ian McEwan Guy Stalnaker, I^2@DOIT, 1210 West Dayton Street, Room 3209 CSS, Madison WI 53719-1220, jstalnak@wisc.edu, work 608.263.8035, cell 608.235.4718, fax 608.265.6681,
Guy wrote:
Well, that lead to an interesting experiment. I used convert to -resample a set of images to 300dpi and redid the compile. They are all now too bod, many off the right side of the page. Then did the same but set to 72. They are still too big. Odd, from too small to too big.
I think you don't want -resample, but -density: # density given in dpi convert pic.jpg -density 72 pic-out.jpg convert -density keeps the pixel size and changes the display size by setting the density metadata. convert -resample keeps the display size and changes the pixel size by resampling at a certain density. (This explains why the picture remained the same too-large size when you resampled at 72 and 300 dpi.) Because you want to change the display size (and also because resampling is a lossy process), I think you want -density. As for the density value you want to use: Your picture is 547px wide, so if you want it to display it 3 inches wide you should set its density metadata to 547/3 = 183 dpi. Does this work? All the best, Sietse
Sietse, I have confirmed, after significant testing, that 'convert -density 72' against existing non-png images produces the expected results in context output pdf documents. But I'm left with another problem, again something that becomes apparent as the difference between having two output formats in my document workflow: markdown -> pandoc -> html/text -> context tex -> pdf. This time it's images that are too wide for the available textarea in the pdf document. Now that the dpi is set, they display at the expected full resolution, yet if they are greater than 6.5*72=438 pixels, they go over the right margin. I know I can, individually, modify each /externalfigure directive and add 'width=\textwidth', but that really is a PITA. This document will have close to a hundred images. I will investigate using a commandline script, exif data, and convert to work through all of the images in the folder to scale/resize them so that they fit in the PDF document margin width. I don't think that the html version will suffer if I do this. So, again, thanks for your help! Best regards, Guy S. On 11/21/2012 02:36 PM, Sietse Brouwer wrote:
Guy wrote:
Well, that lead to an interesting experiment. I used convert to -resample a set of images to 300dpi and redid the compile. They are all now too bod, many off the right side of the page. Then did the same but set to 72. They are still too big. Odd, from too small to too big. I think you don't want -resample, but -density:
# density given in dpi convert pic.jpg -density 72 pic-out.jpg
convert -density keeps the pixel size and changes the display size by setting the density metadata. convert -resample keeps the display size and changes the pixel size by resampling at a certain density. (This explains why the picture remained the same too-large size when you resampled at 72 and 300 dpi.)
Because you want to change the display size (and also because resampling is a lossy process), I think you want -density.
As for the density value you want to use: Your picture is 547px wide, so if you want it to display it 3 inches wide you should set its density metadata to 547/3 = 183 dpi.
Does this work? All the best, Sietse
-- "There is only love, and then oblivion. Love is all we have to set against hatred." (paraphrased) Ian McEwan Guy Stalnaker, I^2@DOIT, 1210 West Dayton Street, Room 3209 CSS, Madison WI 53719-1220, jstalnak@wisc.edu, work 608.263.8035, cell 608.235.4718, fax 608.265.6681, page page-guy@watchdog.doit.wisc.edu
On Fri, 23 Nov 2012, Guy Stalnaker wrote:
But I'm left with another problem, again something that becomes apparent as the difference between having two output formats in my document workflow: markdown -> pandoc -> html/text -> context tex -> pdf. This time it's images that are too wide for the available textarea in the pdf document. Now that the dpi is set, they display at the expected full resolution, yet if they are greater than 6.5*72=438 pixels, they go over the right margin. I know I can, individually, modify each /externalfigure directive and add 'width=\textwidth', but that really is a PITA. This document will have close to a hundred images.
I will investigate using a commandline script, exif data, and convert to work through all of the images in the folder to scale/resize them so that they fit in the PDF document margin width. I don't think that the html version will suffer if I do this.
\setupexternalfigures[maxwidth=\textwidth] Aditya
In case anyone else has been following this thread, here is the shell script I wrote to resize an image width to 6.5x72dpi so they fit in the standard letter pagesize \textwidth with 1-inch margins and add image density/resolution information so that context correctly sizes them in the PDF output file. <code> #!/bin/bash #set -x TEXTWIDTH="438" #6.5inches x 72 dpi for i in *.jpg ; do SIZEX="$(exiftool -imagewidth $i | awk '{print $4}')" SIZEY="$(exiftool -imageheight $i | awk '{print $4}')" echo "Image $i is $SIZEX x $SIZEY, max X is $TEXTWIDTH ..." if [[ $SIZEX > $TEXTWIDTH ]] ; then convert $i -resize $TEXTWIDTH -density 72 $i echo "resized image $i from $SIZEX to $TEXTWIDTH." fi done </code> Regards, Guy On 11/21/2012 02:36 PM, Sietse Brouwer wrote:
Guy wrote:
Well, that lead to an interesting experiment. I used convert to -resample a set of images to 300dpi and redid the compile. They are all now too bod, many off the right side of the page. Then did the same but set to 72. They are still too big. Odd, from too small to too big. I think you don't want -resample, but -density:
# density given in dpi convert pic.jpg -density 72 pic-out.jpg
convert -density keeps the pixel size and changes the display size by setting the density metadata. convert -resample keeps the display size and changes the pixel size by resampling at a certain density. (This explains why the picture remained the same too-large size when you resampled at 72 and 300 dpi.)
Because you want to change the display size (and also because resampling is a lossy process), I think you want -density.
As for the density value you want to use: Your picture is 547px wide, so if you want it to display it 3 inches wide you should set its density metadata to 547/3 = 183 dpi.
Does this work? All the best, Sietse
-- "There is only love, and then oblivion. Love is all we have to set against hatred." (paraphrased) Ian McEwan Guy Stalnaker, I^2@DOIT, 1210 West Dayton Street, Room 3209 CSS, Madison WI 53719-1220, jstalnak@wisc.edu, work 608.263.8035, cell 608.235.4718, fax 608.265.6681, page page-guy@watchdog.doit.wisc.edu
participants (3)
-
Aditya Mahajan
-
Guy Stalnaker
-
Sietse Brouwer