Batch processing SVG to PNG with borders - image-processing

I have an SVG file and I need to export it to PNG in almost 1,000,000 different sizes (height 32-1000px and width 32-1000px).
But there is a catch, the SVG image itself has a width to height ratio of 2:1. So, when the PNG is 400x200 its an easy convert, but when the PNG is 600x200, then there needs to be a whitespace fill on the sides so that the image doesn't get distorted.
Any tools that can do this?

I have made svgexport for that but currently it centers and crops the output instead of padding (now it supports both cropping and padding).

Try inkscape editor. This editor is reference standard for SVG format. Inkscape has rich commandline support for exporting. More info: INKSCAPE manual for command line export

Related

How to change GIMP print size with script-fu

I am using GIMP 2.10.24. I have some image and I need to change Print Size Width to 21mm and Height to 30mm.
I can do that with Set Image Print Resolution Dialog (Menu->Image->Print Size):
screenshot
But there is my question: how could I do that using script-fu or python-fu?
Print size, size in pixels, and print definition are completely related:
print size = size in pixels รท print definition
So to change the image print definition you use
In Python:
pdb.gimp_image_set_resolution(image, xresolution, yresolution)
In Script-fu:
(gimp-image-set-resolution image xresolution yresolution)
In both case the X/Y resolutions are in dots per inch.
However if you are using Gimp just for this creating a Gimp script is overkill (the learning curve is quite steep). If the image is in a common format (JPEG, PNG, TIFF) the print definition is part of the image metadata (JPEG header, or EXIF data) and can be changed directly without decoding/reencoding the image using CLI utilities. For instance with ExifTool:
exiftool ${your_image} -xResolution=321 -yResolution=321

PDF vector graphic smaller than the png at same size

I converted some SVG images into PDF and png files for my iOS app. When adding them to the UIImageView, the pdf images look smaller than the png equivalent. The scale type was set to center, so no scaling happens at runtime.
btw, the pdf and png look the same when I open them in preview and adobe reader
Anyone had same issue and got a solution for that?
When converting an SVG to PDF, make sure the DPI is set to 72. That way, the size will match with the PNG resource that you have. Xcode actually expects vector-based resources to be 1x in size.

Edit image files with Gimp script-fu

I'm trying to edit a pdf file with 100 pages, all of them images I need to export as png, setting their image mode as greyscale, and setting also their resolution, width and heigth.
How can I write a scheme (or python) script that perform this actions so that i could apply them by gimp in batch mode?
I've searched in the internet but didn't find simpy stated instructions.
ImageMagick's convert will do all this in one call in a command prompt:
convert -density 200 -colorspace Gray input.pdf -geometry 1000 ouput.png
will produce 1000px-wide grayscale PNGs (output-0 to output-(N-1).png) using a 200DPI rendering of the PDF.
You can also use Gimp scripting but you'll have a lot more to learn and AFAIK the API for the PDF loader only loads at 100DPI.
A slightly more manual method could be to:
Load (manually) the image in Gimp (you can specifiy the DPI in that case). This loads all the pages as layers.
Image>Mode>RGB to convert the image to grayscale.
Image>Scale image to set the size of all the pages
Save the individual layers to PNG (there are scripts for this, for instance this one)

InDesign Server - Exporting PDF with embedded transparent TIFF images

I'm trying to export a PDF with embedded transparent TIFF images. These images have extremely large dimensions. During the embed process, they are shrunk down to fit in the placeholder frames within the target InDesign file. Because of the dramatic decrease in size, when I then export a PDF from the InDesign file I get a halo affect from the anti-aliasing around the edges of the embedded images. I've had some luck reducing the size of the halo by telling InDesign to not down-sample, but I haven't been able to eliminate it. Does anyone know a way to get rid of this artifact?

Availability of background transparency for jpeg images

I need to edit a png image,by giving it border and drop shadow effect. But the final size of the edited image is too high to use for a mobile app .I know that size of jpeg is less compared to that of png.So i convert that image to jpeg and tried to give drop shadow and border effect.But that image is not having transparent background..Is their any other methods to accomplish this using jpeg?
Another option is to try either ImageOptim for losseless compression, or its lossy cousin, ImageAlpha.
ImageOptim tries a series of lossless algorithms to shrink a PNG and selects the smallest result of the bunch. It has taken 25% to 50%+ of quite a few of our images.
ImageAlpha, on the other hand, is lossy and can further crunch the image, with results more like JPEG but without losing Alpha.
You would also do well to disable PNG compression in Xcode as shown here, with additional details here.
What #minitech wanted to say is not about scaling, it's about file compression. jpg and png files usually have some data that could be removed from the file. There are some compression methods to reduce file size (note that is size in kbs, not in scale measurement). Jpg images can reduce file size by reducing image quality, too.
If you want another file type that accepts transparency, there are the gif format, which gives you a smaller file, but have some drawbacks, like a lack of alpha channel (variable transparency). Check this link for more details: http://www.w3.org/QA/Tips/png-gif
There are a couple of online file compressors. If you want to compress png files, you could try using http://tinypng.org/
No, jpeg image wont support transparency.But you can change the white background coming along with jpeg image

Resources