I have generated a pdf file using matplotlib and I want to add a logo to this pdf file. How can I do it - image

I am using matplotlib to draw a graph using some data and I have saved it in Pdf format.Now I want to add a logo to this file.How can I do this.
Thanks in advance

If you can do it the other way round, it is easier:
plot the image
load the logo from file with, e.g. Image module (PIL)
add the logo with plt.imshow, use the extent keyword to place it correctly
save the image into PDF
(You may even want to plot the logo first, so that it stays in the background.)
Unfortunately, this does not work with vector graphics, but as logos usually are not that large, you may use a .png or even a .jpg.
If you already have the PDF's then this is not a matplotlib or python question. You need some PDF editing tools or libraries to add the logo. Possible, but an entirely different thing.

Related

Bulk identifying images with FFMPEG that contain a graphic

I need to be able to bulk sort through images that contain a graphic and remove these images from the folder. The graphic is a ruler-like image for scale.
I'm a novice with FFMPEG, but have already written a batch script that resizes images. The logic seems pretty understandable, however my issue is that I don't know what and where to research for a solution to my problem. From what I read, imagemagik might also be a great tool, but I feel more comfortable with FFMPEG.
I expect the script to look through all image files in a folder and find those the contain the ruler graphic and remove the said images with the rule graphic from the folder. The images are product shots on white backgrounds and the rule graphic is not overlaying anything or acting like a watermark.
Ideally, if possible, a way to crop out the graphics would be an amazing next step.

Create small high quality PDF embedding optimized PNG?

I'm trying to create a small PDF file, embedding one optimized PNG image displayed as a header and footer on a 3 page PDF (same image must appear 6x in the PDF)
My optimized PNG image is only 2.3KB. It looks very sharp.
Failed with libreoffice
When I insert just one instance of the 2.3KB PNG image into a Libreoffice Writer doc containing only text, then export as PDF I can see that the image gets re-compressed to JPG and the resulting PDF file grows by about 40KB after adding the image. It also loses quality, the PNG also gets JPG fuzzy edges.
If I right click the image and select compression, there is no way to disable recompressing the image (it's already optimized better than libreoffice could do it) I've tried setting a compression level of 0,1,9 etc. Choosing JPG, no resize, lossless, etc but there was no improvement.
Failed with wkhtmltopdf
I also tried making a test page and used wkhtml2pdf but it did the same thing. Adding the low quality flag made no difference.
PDF Spec suggests PNG is supported?
From skimming the PDF spec, it looks like PNG images are supported.
Even plain text PDF files are surprisingly large
The disappointing thing is also when I take a 7KB HTML file which is basically just <html><body><p>foo...</p><p>bar...</p> (only about 15 paragraphs) with no CSS. The resulting 2 page PDF file is 30KB. Why should a 7kb (almost plain text) file become 30kb as a PDF?
Suggestions?
Can someone please suggest how to make a small PDF file in Linux?
I need to include 7KB of text and repeat one PNG image 6 times.
Manually or programatically. I'll take whatever I can get at this point.
PDF Spec suggests PNG is supported?
PNG isn't supported per se; PDF allows embedding JPEG images as-is, but not PNG images. PDF does borrow a set of features of the PNG format, however.
rinohtype (full disclosure: I'm the author) tries to embed as much as possible from PNG images as-is into the PDF. This does involve some bit-juggling to separate the alpha channel from the color data for example, but no reencoding of the image is performed. It does not (yet) support interlaced PNGs.
rinohtype should be able to do what you want to achieve. But please note that it currently is in a beta stage, so you might encounter some bugs.
Even plain text PDF files are surprisingly large
To keep the PDF size as small as possible, make sure not to embed/subset any of the fonts. Use only the fonts from the base 14 PDF fonts which are provided by PDF readers.
What you want is certainly achievable. Regarding the image quality, I would recommend making your image twice the size that you want it to actually display at in the PDF to keep it looking sharp.
As to the size, I've just modified a test in my PDF writer module (WIP..) to include a 7.2K png, 200px x 70px, in a PDF twice and the PDF came out at 6.8K 8). There's not much text included, but more text will only add what it's worth + a small percentage.
You can see the module and original test here.. https://github.com/DoccaPDF/docca-pdf-writer/blob/master/src/tests/writer.js#L40
That test adds ~112K of images to the PDF and results in a 103K PDF.
Of course not all images are created equal so you milage may vary..
*the images are only actually added to the PDF once, but are displayed multiple time.

Inkscape - Not fully converting png into svg

I opened one PNG file in Inkscape and exported it as SVG. When I opened that file with notepad I came to know that the PNG file is embedded within it. If the conversion happened then the resulting file should have only SVG related tags. It shouldn't embed the image within it. Or Am I doing anything wrong.
Note: Save as option also producing the same kind of file. I am using Inkscape version 0.48 in Windows 7 - 64 bit.
This is a bit of an old thread, but it comes up early in Google so I thought I'd contribute something.
In Inkscape, you must do a trace to change the image into SVG. Look at the Path | Trace bitmap menu item and play with the options on that screen.
After creating the trace, you can remove your source image and have a pure svg in your saved file.
I've found it helpful to create layers in Inkscape and move the source image to one layer and put the trace on another layer to let me make quick comparisons using the 'hide layer' buttons.
BTW, your source image can be anything - bmp, jpg, png, etc.
A .png file is a raster image file. In order to convert it to a vector graphic based format like .svg and have it be "native" svg rather than an included image you are going to either have to use a program that can rasterize it or in Inkscape trace the bitmap and turn it into paths. Inkscape provides information on tracing: http://inkscape.org/doc/tracing/tutorial-tracing.html

Convert SVG to image

How do I convert an svg file to an image using Go ?
I found the amazing svgo library and would like to use it to generate a custom set of playing cards. The idea is to store the text and layout of a card in a text file and then read and process it with go. This would be a huge improvement of my current workflow where I use gimp to edit each individual card. The problem is that I need to have an image of the card for printing. Preferably png since the printing script so far only works with that format. But I could easily adapt it to accept jpeg, too.
Unfortunately svgo doesn't seem to offer export functionality. Can you recommend a go library to convert svg to png ?
One possible strategy is to write your SVG to files and invoke an external tool to convert them. For example, ImageMagick and its related GraphicsMagick will both convert SVG to PNG via command-line options. You would need to use the convert verb, possibly within their batch support if you're converting lots of images at once.
GraphicsMagick has bindings for C and Go and other languages that you could use directly from your Go scripts, although I've not tried this myself.
I can't find a native Go library to do it, but there seems to be a way to convert an HTML canvas element to PNG quite simply in Javascript.
You can therefore output SVG to an HTML canvas element, and then use JS to export to SVG.
See this answer for details.

How to convert Autocad drawing to image?

I have an Autocad drawing which is a plan for land squares where each square contains a number.
I tried to convert it to image by choosing: File --> Export Data --> and file format Bitmap (bmp). (I have Autocad 2013 Mac version)
the file converted to image, but the quality is too bad, I can't see the land numbers inside the square when I zoom in the image.
I tried also with Postscript (PS file format), quality is a bit better but it's still bad.
Is there away to convert Autocad file to image but still preserve it's high quality details
I need to convert the file to image because I would like to publish it online on my website. maybe there other was to publish autocad file on line, if so, please advice. But the trick I want the background of the autcad (plan) to be transparent so that I could display it on top of Google maps. I if I used autocad plugin I can't make it transparent. right?
Use the PLOT (for the current drawing) or PUBLISH (for batching) commands to produce high quality images.

Resources