A detail that matters - please help

50 views
Skip to first unread message

Marc Culler

unread,
Jun 28, 2023, 10:23:47 AM6/28/23
to sage-release
Details really do matter.  The devil is in them.  Here is one which makes a major difference to my efforts to distribute Sage.  I hope that I can convince people to pay attention to it.

DETAIL: An svg image can be compressed very efficiently and will look good at all resolutions.  A png image can not be compressed, being already compressed, and pixelates at high resolutions.

BACK STORY: I am working on adding documentation to the Sage_macOS distribution.  Size is important.  For 10.1beta3 the English documentation occupied 631MB, and compressed down to 104MB.  For 10.1beta4 the uncompressed size increased by over 100MB due to the addition of 100MB of png images.  Now it only compresses to 207MB, doubling the compressed size.

There is no need for this wastefulness.  Here is an example:

sage: D = graphs.DodecahedralGraph()
sage: p = D.plot()
sage: p.save_image('/tmp/dodec.svg')
sage: p.save_image('/tmp/dodec.png')

The result:
% ls -l /tmp/dodec*
-rw-r--r--@ 1 culler  wheel  42735 Jun 28 08:48 /tmp/dodec.png
-rw-r--r--  1 culler  wheel  18524 Jun 28 08:48 /tmp/dodec.svg
% gzip /tmp/dodec*
% ls -l /tmp/dodec*
-rw-r--r--@ 1 culler  wheel  39473 Jun 28 08:48 /tmp/dodec.png.gz
-rw-r--r--  1 culler  wheel   3815 Jun 28 08:48 /tmp/dodec.svg.gz

BOTTOM LINE: we get more than a 90% reduction in size simply by choosing to use the .svg extension when saving the plot instead of the .png extension.

I am not allowed to upload an svg file to google groups, so you will have to verify for yourself that the svg looks better than the png, but it does.

- Marc


Vincent Delecroix

unread,
Jun 28, 2023, 11:49:51 AM6/28/23
to sage-r...@googlegroups.com
I agree with Marc that svg is almost always preferable than png for
graphics : it scales and compresses. Thanks for raising the issue.

Do you have a concrete proposal for making the change png -> svg
happen? I guess there is a lot of files that would be involved in the
transition.

Vincent
> --
> You received this message because you are subscribed to the Google Groups "sage-release" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-release...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-release/8ce7a804-3be1-4551-959e-cc770fe589ecn%40googlegroups.com.

John H Palmieri

unread,
Jun 28, 2023, 12:13:21 PM6/28/23
to sage-release
I think this should be discussed at sage-devel.

Marc Culler

unread,
Jun 28, 2023, 12:13:35 PM6/28/23
to sage-release
As far as I can tell it is a choice that is being made at various places in the sage_docbuild module to use png as the default image format.  But I haven't been able to find exactly where.  One place appears to be line 117 in src/sage_docbuild/conf.py, but that is not the only place.

- Marc

Dima Pasechnik

unread,
Jun 28, 2023, 12:17:24 PM6/28/23
to sage-release


On Wed, 28 Jun 2023, 17:13 John H Palmieri, <jhpalm...@gmail.com> wrote:
I think this should be discussed at sage-devel.

are there any setbacks in using svg nowadays?

Harald Schilly

unread,
Jun 28, 2023, 12:31:01 PM6/28/23
to sage-r...@googlegroups.com
On Wed, Jun 28, 2023 at 6:17 PM Dima Pasechnik <dim...@gmail.com> wrote:
are there any setbacks in using svg nowadays?


The only fundamental issue is file size. It's proportional to the number of elements you want to plot. So, e.g. when there are a million points, you end up with a million lines of text in the svg – while with a raster image format like png, the points are "fused" to a large blob and file size stays constant or even decreases. My guess is, all those plots in the documentation have only a small number of elements, so, all fine :-)

-- Harald



 

Marc Culler

unread,
Jun 28, 2023, 12:39:27 PM6/28/23
to sage-release
No, that is not correct.  The fundamental issue is the size of the compressed file.  And this is an issue with documentation, not with arbitrary graphics.  The matplotlib images in the Sage documentation do not involve millions of lines of svg code.  The svg files are small to start with and compress very efficiently.  Of course it would be possible to generate images which are naturally rasterized and would be very inefficiently represented by svg.  But that is not happening with the matplotlib images in the documentation.

- Marc
Reply all
Reply to author
Forward
0 new messages