\externalfigure and file size
Hey list, I have a number of \externalfigure commands to typeset some svg images. This is often handy to have them vectorized because it allows for the user to zoom in on diagrams of great detail. In other situations, I find that for images that are not so important, they would benefit from ConTeXt rasterizing them when they are imported. The reason for this is I find some vector images get enormously bloated when they are typeset. As an example, I have a Logo.svg of only 6.8 KB. The m_k_i_v_Logo.pdf intermediate ConTeXt generates is nearly a megabyte in size. Why? I have no idea, as they both appear to be the same image with the same gausian blur. Is there a flag I can pass certain instances of \externalfigure that tells the image processing backend that a simple rasterized version of the figure is fine? Or is there a better approach? I don't want to pre-convert all of these images to raster formats. -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On Thu, Jan 19, 2012 at 01:25, Kip Warner
In other situations, I find that for images that are not so important, they would benefit from ConTeXt rasterizing them when they are imported. The reason for this is I find some vector images get enormously bloated when they are typeset. As an example, I have a Logo.svg of only 6.8 KB. The m_k_i_v_Logo.pdf intermediate ConTeXt generates is nearly a megabyte in size. Why? I have no idea, as they both appear to be the same image with the same gausian blur.
If original svg image is 7 KB, the PDF should not be any bigger apart from the header and maybe embded fonts. However if you are using some smooth shading, it might be that the program which does the conversion is performing a poor job and converts shading into hundreds of thin strips of different colors. I would try to use a different tool for conversion into PDF (not into raster image, but into vector image) before running ConTeXt. I don't know which one, but you can try to experiment. Mojca
On Thu, 2012-01-19 at 08:56 +0100, Mojca Miklavec wrote:
If original svg image is 7 KB, the PDF should not be any bigger apart from the header and maybe embded fonts. However if you are using some smooth shading, it might be that the program which does the conversion is performing a poor job and converts shading into hundreds of thin strips of different colors.
I'm not sure what program is being used, as I just call context and whatever its using to take the svg specified in the \externalfigure to typeset is what it seems to be using. -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On Thu, Jan 19, 2012 at 1:25 AM, Kip Warner
Hey list,
I have a number of \externalfigure commands to typeset some svg images. This is often handy to have them vectorized because it allows for the user to zoom in on diagrams of great detail.
In other situations, I find that for images that are not so important, they would benefit from ConTeXt rasterizing them when they are imported. The reason for this is I find some vector images get enormously bloated when they are typeset. As an example, I have a Logo.svg of only 6.8 KB. The m_k_i_v_Logo.pdf intermediate ConTeXt generates is nearly a megabyte in size. Why? I have no idea, as they both appear to be the same image with the same gausian blur.
Is there a flag I can pass certain instances of \externalfigure that tells the image processing backend that a simple rasterized version of the figure is fine? Or is there a better approach? I don't want to pre-convert all of these images to raster formats.
ConTeXt uses inkscape, iirc. So try to see what inkscape says about your file. If you are under linux, you can also use rsvg . -- luigi
On Thu, 2012-01-19 at 09:23 +0100, luigi scarso wrote:
ConTeXt uses inkscape, iirc. So try to see what inkscape says about your file.
Are you sure about that? ConTeXt doesn't seem to list inkscape as a dependency on my distro: apt-cache show context* | grep -i inkscape (gives nothing) -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On 2012-01-19 Kip Warner
On Thu, 2012-01-19 at 09:23 +0100, luigi scarso wrote:
ConTeXt uses inkscape, iirc. So try to see what inkscape says about your file.
Are you sure about that?
Yes: strace -f context t 2>&1 >/dev/null | grep inkscape | grep execve […] [pid 14816] execve("/usr/bin/inkscape", ["inkscape", "/home/marco/Temp/fig.svg", "--export-dpi=600", "-A", "/home/marco/Temp/m_k_i_v_fi"...], […]
ConTeXt doesn't seem to list inkscape as a dependency on my distro:
Inkscape should not be a dependency of ConTeXt. 99.9% work very well without inkscape. But it could be mentioned as a “Recommendation”, as a hint that its installation would increase the functionality.
apt-cache show context* | grep -i inkscape (gives nothing)
Blame the distributor. Marco
On Fri, 2012-01-20 at 01:51 +0100, Marco wrote:
Blame the distributor.
I just forwarded your observation to the package maintainer. Should be straightforward to solve with a line in debian/control. -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On 20-1-2012 01:51, Marco wrote:
ConTeXt doesn't seem to list inkscape as a dependency on my distro:
Inkscape should not be a dependency of ConTeXt. 99.9% work very well without inkscape. But it could be mentioned as a “Recommendation”, as a hint that its installation would increase the functionality.
There is no such depedency .. actually, i found it rather impossible to get an inkscape running on a headless linux box as there is some depedency on X (last time I tried). In a similar fashion there is no dependency on GhostScript or GraphicMagick or Zint. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Fri, 2012-01-20 at 10:08 +0100, Hans Hagen wrote:
There is no such depedency .. actually, i found it rather impossible to get an inkscape running on a headless linux box as there is some depedency on X (last time I tried). In a similar fashion there is no dependency on GhostScript or GraphicMagick or Zint.
So what does ConTeXt do when it typesets an \externalfigure? Does it always use inkscape, or only sometimes? -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On 21-1-2012 00:05, Kip Warner wrote:
On Fri, 2012-01-20 at 10:08 +0100, Hans Hagen wrote:
There is no such depedency .. actually, i found it rather impossible to get an inkscape running on a headless linux box as there is some depedency on X (last time I tried). In a similar fashion there is no dependency on GhostScript or GraphicMagick or Zint.
So what does ConTeXt do when it typesets an \externalfigure? Does it always use inkscape, or only sometimes?
no, png, jpg and pdf are supported directly (as is mp) but fo rother formats it will either try to find a replacement (there is a whole chain of lookups) or it will try to run one of the configured converters ... with \enabletrackers[graphics.*] you can see what happens ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Sat, Jan 21, 2012 at 1:07 AM, Hans Hagen
On 21-1-2012 00:05, Kip Warner wrote:
On Fri, 2012-01-20 at 10:08 +0100, Hans Hagen wrote:
There is no such depedency .. actually, i found it rather impossible to get an inkscape running on a headless linux box as there is some depedency on X (last time I tried). In a similar fashion there is no dependency on GhostScript or GraphicMagick or Zint.
So what does ConTeXt do when it typesets an \externalfigure? Does it always use inkscape, or only sometimes?
no, png, jpg and pdf are supported directly (as is mp) but fo rother formats it will either try to find a replacement (there is a whole chain of lookups) or it will try to run one of the configured converters ... with
and swf, even if I have not full tested (basically you can test only with acroreader 10) -- luigi
On 21-1-2012 01:12, luigi scarso wrote:
On Sat, Jan 21, 2012 at 1:07 AM, Hans Hagen
wrote: On 21-1-2012 00:05, Kip Warner wrote:
On Fri, 2012-01-20 at 10:08 +0100, Hans Hagen wrote:
There is no such depedency .. actually, i found it rather impossible to get an inkscape running on a headless linux box as there is some depedency on X (last time I tried). In a similar fashion there is no dependency on GhostScript or GraphicMagick or Zint.
So what does ConTeXt do when it typesets an \externalfigure? Does it always use inkscape, or only sometimes?
no, png, jpg and pdf are supported directly (as is mp) but fo rother formats it will either try to find a replacement (there is a whole chain of lookups) or it will try to run one of the configured converters ... with
and swf, even if I have not full tested (basically you can test only with acroreader 10)
sure, a few of those 'supported media types' are also dealt with (in fact I think that one can embed svg in a pdf document given some plugin Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Sat, 2012-01-21 at 01:07 +0100, Hans Hagen wrote:
no, png, jpg and pdf are supported directly (as is mp) but fo rother formats it will either try to find a replacement (there is a whole chain of lookups) or it will try to run one of the configured converters ... with
\enabletrackers[graphics.*]
you can see what happens
I tried the above command and it didn't appear to do anything. =( -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On 2012-01-20 Kip Warner
So what does ConTeXt do when it typesets an \externalfigure? Does it always use inkscape, or only sometimes?
If the image type is supported by the TeX engine (jpeg, png, pdf, mps) it is directly included. SVG files inkscape is called to convert the SVG to PDF. For EPS images ghostscript is used: strace results: execve("/usr/bin/gs", ["gs", "-q", "-sDEVICE=pdfwrite", "-dNOPAUSE", "-dNOCACHE", "-dBATCH", "-dAutoRotatePages=/None", "-dPDFSETTINGS=/prepress", "-dEPSCrop", "-sOutputFile=m_k_i_v_graph.pdf", "graph.eps", "-c", "quit"], [/* 55 vars */]) Marco
I just tested now. With Inkscape 0.48.2 r9819, I could do the conversion
job on pure console.
But, on the other hand, as nothing is perfect, to install Inkscape, it's
needed many X dependencies.
On 20 January 2012 06:08, Hans Hagen
There is no such depedency .. actually, i found it rather impossible to get an inkscape running on a headless linux box as there is some depedency on X (last time I tried).
Am 19.01.2012 01:25, schrieb Kip Warner:
Hey list,
I have a number of \externalfigure commands to typeset some svg images. This is often handy to have them vectorized because it allows for the user to zoom in on diagrams of great detail.
In other situations, I find that for images that are not so important, they would benefit from ConTeXt rasterizing them when they are imported. The reason for this is I find some vector images get enormously bloated when they are typeset. As an example, I have a Logo.svg of only 6.8 KB. The m_k_i_v_Logo.pdf intermediate ConTeXt generates is nearly a megabyte in size. Why? I have no idea, as they both appear to be the same image with the same gausian blur.
Probably because the exported PDF contains a raster image (at least the blured part). If you use Inkscape to save your SVG logo as PDF, you will see a dialog box with an option for this (rasterize filter effects). Remove the hook and you'll get a small, but unblured PDF graphic. Best wishes, Peter
On Thu, 2012-01-19 at 11:58 +0100, Peter Rolf wrote:
Probably because the exported PDF contains a raster image (at least the blured part). If you use Inkscape to save your SVG logo as PDF, you will see a dialog box with an option for this (rasterize filter effects). Remove the hook and you'll get a small, but unblured PDF graphic.
Hey Peter. The original SVG is about 7KB. With rasterize off and exported to PDF, its under 2KB. With rasterize on, its still only 78KB. Whatever ConTeXt is doing with it, that 7KB SVG gets bloated to nearly a meg at 976KB. This happens as Logo.svg is transformed into intermediate m_k_i_v_Logo.pdf. Something's up. -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On Thu 19 Jan 2012, Kip Warner wrote:
Hey Peter. The original SVG is about 7KB. With rasterize off and exported to PDF, its under 2KB. With rasterize on, its still only 78KB. Whatever ConTeXt is doing with it, that 7KB SVG gets bloated to nearly a meg at 976KB. This happens as Logo.svg is transformed into intermediate m_k_i_v_Logo.pdf. Something's up.
What happens if you convert it directly using inkscape --export-pdf? Pont
On Fri, 2012-01-20 at 13:07 +1300, Pontus Lurcock wrote:
What happens if you convert it directly using inkscape --export-pdf?
Still only 78 KB. -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On Fri, Jan 20, 2012 at 01:23, Kip Warner wrote:
On Fri, 2012-01-20 at 13:07 +1300, Pontus Lurcock wrote:
What happens if you convert it directly using inkscape --export-pdf?
Still only 78 KB.
Does it come out the way you expect it to? If yes, use that. None of my tools are able to export this into an usable PDF (I didn't try to install Inkscape though). But it is also true that I'm not 100 % sure if PDF knows anything about the "gaussian blur". Mojca
On Fri 20 Jan 2012, Mojca Miklavec wrote:
None of my tools are able to export this into an usable PDF (I didn't try to install Inkscape though). But it is also true that I'm not 100 % sure if PDF knows anything about the "gaussian blur".
I think this is the root of the problem: inkscape rasterizes it to reproduce the blur in PDF, and explicitly setting the DPI to a high value produces the huge file. Discussed at: http://www.inkscapeforum.com/viewtopic.php?f=6&t=9551 http://wiki.inkscape.org/wiki/index.php/Release_notes/0.47#PDF.2C_PostScript... Pont
On Fri, 2012-01-20 at 01:45 +0100, Mojca Miklavec wrote:
Does it come out the way you expect it to? If yes, use that.
Visually, yes, it's fine. In terms of size, no its not the way I expect.
None of my tools are able to export this into an usable PDF (I didn't try to install Inkscape though). But it is also true that I'm not 100 % sure if PDF knows anything about the "gaussian blur".
I think you've hit the nail on the head. I think the problem is the PDF format chokes on the Gaussian blur and so it has to rasterize it. -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
It would be good if you attach the svg file.
Could you do this?
--
Wagner Macedo
On 19 January 2012 21:01, Kip Warner
Hey Peter. The original SVG is about 7KB. With rasterize off and exported to PDF, its under 2KB. With rasterize on, its still only 78KB. Whatever ConTeXt is doing with it, that 7KB SVG gets bloated to nearly a meg at 976KB. This happens as Logo.svg is transformed into intermediate m_k_i_v_Logo.pdf. Something's up.
On Thu, 2012-01-19 at 21:13 -0300, Wagner Macedo wrote:
It would be good if you attach the svg file.
Could you do this?
Hey Wagner. No problem. http://www.thevertigo.com/temp/Pic.svg Try typesetting it with an \externalfigure and check the file size of the intermediate that's generated. -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On Thu 19 Jan 2012, Kip Warner wrote:
On Thu, 2012-01-19 at 21:13 -0300, Wagner Macedo wrote:
It would be good if you attach the svg file.
Could you do this?
Hey Wagner. No problem.
My PDF file sizes (using 2011.10.01 10:48): ConTeXt : 978k inkscape -A : 75k inkscape --export-dpi=600 -A : 978k So it seems that the dpi parameter passed by ConTeXt to Inkscape is responsible for the huge size increase. Pont
Am 20.01.2012 um 01:01 schrieb Kip Warner:
On Thu, 2012-01-19 at 11:58 +0100, Peter Rolf wrote:
Probably because the exported PDF contains a raster image (at least the blured part). If you use Inkscape to save your SVG logo as PDF, you will see a dialog box with an option for this (rasterize filter effects). Remove the hook and you'll get a small, but unblured PDF graphic.
Hey Peter. The original SVG is about 7KB. With rasterize off and exported to PDF, its under 2KB. With rasterize on, its still only 78KB. Whatever ConTeXt is doing with it, that 7KB SVG gets bloated to nearly a meg at 976KB. This happens as Logo.svg is transformed into intermediate m_k_i_v_Logo.pdf. Something's up.
When you look into graph-inc.lua you can see that context use inkscape <oldname> --export-dpi=600 -A <newname> to convert the svg to pdf. Wolfgang
On Fri, 2012-01-20 at 01:14 +0100, Wolfgang Schuster wrote:
When you look into graph-inc.lua you can see that context use
inkscape <oldname> --export-dpi=600 -A <newname>
to convert the svg to pdf.
Hey Wolfgang. Why does a vector image need to be rasterized in a PDF, I guess is what I'm still confused with? It seems like DPI is a concept applicable only to rasterized graphics. Or is it that the PDF backend is normally fine with vector graphics, it's just that this one in particular contains a Gaussian blur that it has to rasterize because it cannot dynamically reproduce? -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On 2012-01-19 Kip Warner
Whatever ConTeXt is doing with it, that 7KB SVG gets bloated to nearly a meg at 976KB. This happens as Logo.svg is transformed into intermediate m_k_i_v_Logo.pdf.
I had similar issues some weeks ago. A workaround was to use \pdfcompresslevel9 You can also try \maximumpdfcompression, which is apparently preferred (see some recent thread on the list). Marco
On Fri, 2012-01-20 at 01:21 +0100, Marco wrote:
I had similar issues some weeks ago. A workaround was to use \pdfcompresslevel9 You can also try \maximumpdfcompression, which is apparently preferred (see some recent thread on the list).
Marco
Thanks Marco. It went from 9.9 MB to 9.5 MB. It's a small delta, but still helpful. On a related note, what is the difference between these three statements? \setupbackend[level=9] \pdfcompresslevel9 \maximumpdfcompression -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com
On 2012-01-19 Kip Warner
On a related note, what is the difference between these three statements?
\setupbackend[level=9]
I have no idea, I never used it.
\pdfcompresslevel9
AFAIK it compresses the text objects. 9 is maximum compression. It's a low level command.
\maximumpdfcompression
\normalprotected\def\maximumpdfcompression{% \pdfobjcompresslevel\plusnine \pdfcompresslevel\plusnine } Sets the text and object compression to the maximum value (which is 9). The command is considered to be a higher level command, see http://archive.contextgarden.net/message/20111229.184755.b0199f53.en.html Marco
On 20-1-2012 11:18, Marco wrote:
Sets the text and object compression to the maximum value (which is 9). The command is considered to be a higher level command, see
http://archive.contextgarden.net/message/20111229.184755.b0199f53.en.html
keep in mind that on the average the defaults are a good compromise between speed and bytes (both in writing and reading) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (9)
-
Hans Hagen
-
Kip Warner
-
luigi scarso
-
Marco
-
Mojca Miklavec
-
Peter Rolf
-
Pontus Lurcock
-
Wagner Macedo
-
Wolfgang Schuster