faster download: png or svg? - http

I was told once that code is faster to download than image files. Is this true, or is file size the only factor that matters?
For example, I have an SVG file that is a complex illustration. This SVG file is 3.5mb, after optimization using SVGOMG.
I also rendered the illustration as a PNG file. The PNG version has file size of only 153k, after optimization using ImageOptim.
In this scenario, is it true that an SVG file download is faster because it is code - as opposed to a bitmap? OR is the file size the only factor that determines download speed?
The reason I am considering SVG is to preserve the detail of the illustration.

Related

Qt: Saving an image in intended compression format

I am using Qt and saving a image file out of a QML UI item. Following is what I do
auto screenshot = quick_item->grabToImage();
screenshot->saveToFile("/somepath/filename.jpeg");
// OR sometimes use like png like
screenshot->saveToFile("/somepath/filename.png");
This is works fantastically well on all platforms. I open the file the image is saved as intended.
Now my question is:
I just mentioned .jpeg as file extension while providing the filename as param into saveToFile. This works but, should I need to use QImageWriter to ensure that the image is actually compressed in jpeg/png format ?
What happens when it is a lossy compression like jpeg?
How to control a lossy compression if I want to like in android I can do a image.compress(CompressFormat.JPEG, 80, stream) where 80 is the percentage of quality for Compress ?
You can't do that directly from QQuickItemGrabResult, you have to use QImage::save() for that :
auto screenshot = quick_item->grabToImage();
auto image = screenshot->image();
image.save("/somepath/filename.jpeg", nullptr, 80);
The second parameter of save is the format, but it can be left null and then be guessed based on the filename extension, the third one is the compression quality.
The quality factor has no effect if you use a lossless format like png. You can set it at -1 (the default value), omit the parameter or use a factor that you would use for lossy format.
EDIT: as pointed by #Arsenal, the quality factor maps to compression levels for lossless formats (those that support it). For example in PNG, quality 0 maps to PNG compression level 9 (smallest file size) and 100 to PNG compression level 0 (biggest file size). The default quality for PNG in Qt is 50, mapping to a PNG compression level of 4.

Can I reduce pdf file size in knitR/ggplot2 when using a large dataset without using external tools?

I have a number of large-ish files which I am reading into R in an rmarkdown document, cleaning up, and plotting with ggplot2.
Most files are about 3Mb in size with around 80,000 lines of data, but some are 12Mb in size, with 318,406 lines of data (Time, Extension, Force).
Time,Extension,Load
(sec),(mm),(N)
"0.00000","0.00000","-4.95665"
"0.00200","0.00000","-4.95677"
"0.00400","0.00000","-4.95691"
"0.10400","-0.00040","-4.95423"
It takes a while to churn through the data and create the pdf file (that's OK), but the PDF file is now nearly 6Mb in size with about 16 graphs in there (in fact 3 graphs which are facet plots using ggplot2).
I understand that the pdf is including a line segment for every datapoint in my dataset, and therefore as I increase the number of graphs the amount of data in the file increases./ However, I don't forsee a requirement to drill down into the pdf document to see that level of detail, and I will have problems emailing it around as it approaches 10Mb).
If I convert pdf to ps using pdf2ps and then go back to pdf with ps2pdf, I get a file about 1/3 of the size of the original pdf, and the quality looks great.
Therefore is there a method from within R/knitR/ggplot2 to reduce the number of points plotted in the pdf images without using an external tool to compress the pdf file ? (or to somehow optimise the pdf generated ?)
Cheers
Pete
You can try changing the graphic device from pdf to png by adding
knitr::opts_chunk$set(dev = 'png')
to your setup chunk.
Or you can add this to your output header
output:
pdf_document:
dev: png
Try different devices (png, jpg). Maybe this will change the size

Slow rendering with image | MigraDoc

I am creating a PDF using MigraDoc and have now ran into a little problem. I am using a A4 size image (2480px x 3508px / 96KB in size) as a background for my PDF using the following code:
Dim frame = Section.Headers.FirstPage.AddTextFrame
frame.AddImage("background.png")
frame.WrapFormat.Style = WrapStyle.Through
frame.RelativeHorizontal = RelativeHorizontal.Page
Using this causes the PDF to render around 10 times longer (say 10 seconds) then without or a smaller sized file (say 1 second). Is there anyway to speed this up?
I have tried to not use a frame thinking this could be the problem displaying the image using:
Dim backing As Image = Section.Headers.FirstPage.AddImage("background.png")
But still the same results, the reason I want time cut down is I create up to 1000 of these and this can take a long time at the current speed.
I cant downsize the image any more but I don't see why it should be a problem with the size. If this is the problem and there is no way around it please do let me know.
Maybe it goes faster when you use a JPEG file (if that is an option).
JPEG files are copied into the PDF as they are. PNGs and other formats have to be converted into "PDF images".
You can use pages from PDF files just like images. This is another option you can try: once create a PDF with your background image, and create all other files with that PDF instead of the PNG (if JPEG is not appropriate for your image).
There are two builds of MigraDoc: one using GDI+, one using WPF. You could try both to see if that makes a difference.
BTW: Images can be positioned like TextFrames, so there is no need to put an Image into a TextFrame.

Programmatically setting .eps files to CMYK (as opposed to RGB)

We have an app where we need to export files from vector files from Inkscape to .eps to be used for printing. While this is working fine, our printers have complained that they are receiving the files in RGB mode instead of CMYK.
Is there a way to programmatically set .eps files to CMYK document color mode?
Color mode isn't a setting like, say, DPI. Converting from RGB to CMYK for printing is a complex process, often involving color spaces, halftoning, and other nontrivial algorithms.

Extracting path data from an SVG map to use in RaphaelJs

I'm trying to build an an interactive map using RaphaelJS (e.g. http://raphaeljs.com/australia.html). Please check the source. It requires map path data to input. There is no clear explanation anywhere about how to obtain this information, other than the fact that illustrator or inkscape are capable of doing it.
I'm looking to obtain "States" path data from this India map: http://en.wikipedia.org/wiki/File:India-locator-map-blank.svg
well, this one is easy. SVG is just a simple XML file. So you don't have to "extract" anything via Illustrator.
Just open the SVG in any text editor and it's all there! (the path data string you can use with RaphaelJS path-function is held in the d-attribute of the path nodes).
Watch our for copyright issues when using SVG files of others ;)
Skunks
You could also use a converter like Ready.Set.Raphael to extract the paths for you and create the javascript output. It's a real time saver!
For older SVG files the path data will need to be optimized for RaphaelJS. Open the file in Inkspace and save as Optimized AVG. If you have an AVG file that opens as a blank image in Adobe Illustrator, edit the file with a text editor and set the first two values of the viewBox to 0,0. Both steps may be required when working with map AVG files from Wikipedia.

Resources