Lossless PDF rotation - python

is there a way to rotate a PDF 90 degrees losslessly, with Python or using the command line?
I'm looking for a REAL rotation, not just adding a "/ROTATE 90" inside the PDF, because afterwards I have to send the PDF via Hylafax and it looks like that it ignores those commands.
I tried with ImageMagick's convert but the quality of the resulting PDF is quite low.
(Python 2.6.2, Xubuntu 9.04)
Thanks for your attention!

In the pdfjam package there is a shell script pdf90 which does the rotation via pdflatex.

The best resolution you will normally obtain from a standard fax machine is about 200dpi; standard faxes are about 100dpi. If you need your faxed documents to work with an artitrary fax machine you can't go above this.
Ergo, rendering your PDF to a 100 or 200dpi bitmap and rotating it 90 degress should work as well as anything. Various ghostscript based tool chains can do the rendering. Alternatively, there are a number of PDF and postscript based tools that can do this type of manipulatiion (e.g. PDF2PS and psutils) directly off the PDF.

Related

How to retrieve data points from chart image?

I have some time series plots I've done a long time ago that I would like to improve in terms of graphics and style. However, I didn't save the raw data and I cannot recover them.
So I was wondering, is there a way to retrieve data points from a chart image (e.g. png file)? like I input an image and I get a csv/dataframe/array with pairs of x,y coordinates?
To give an idea, that's the kind of images I would like to convert:
I've seen this GRABIT could potentially work but I'm not familiar with MatLab. Is there anything python-based or possibly some web tools?
Preferences:
work on linux systems (in particular ubuntu)
doesn't require installation
there is a little and simple software develop here in Brazil that can do this kind of thing.
You have to download in the following link:
http://paginapessoal.utfpr.edu.br/lasouza/analise-nao-linear-de-estruturas/Pega%20Ponto%201.0.exe/view
You can load the image, specify the origin and set the x and y labels. After you can retrieve the points that you clicked on the image.

How to read SEQ files produced by FLIR thermal infrared cameras?

I have some thermal infrared videos in .SEQ format captures with a FLIR camera. I can view them using FLIR Tools software, but I would like to instead read them into python, with every frame of the video being a numpy array containing temperature brightness values in each pixel.
I saw that the flirpy library (https://flirpy.readthedocs.io/en/latest/getting_started/seq.html) is able to covert .SEQ files to a different format, but I haven’t found any code examples for this, or any tool that can open the .SEQ files directly in python. If possible, I would prefer to work with the thermal files directly in python rather than covert them to a different file format.
There ist a file sdk from FLIR:
https://github.com/gcathelain/thermalcognition/tree/master/FLIR%20Science%20File%20SDK
the FileSDK can also be downloaded from FLIR directly: https://flir.custhelp.com/app/answers/detail/a_id/3504/~/getting-started-with-flir-science-file-sdk-for-python
Then you can install it directly for different python versions or also buiild wheel-files for an easier usage.
This directly supports the read out of the .seq-files via the package fnv. For me this is working fine and much faster than splitting by marker, which is sometimes done.

How to insert vector graphics (SVG) to a raster image such as JPG/TIF programmatically (Python/JS/C++)?

I need a programmatic way to embed a clipping-path (saved as SVG file) to another image such as JPG/TIF/PSD. Using a tool such as Photoshop, this can be done easily and the path will be inserted in the image 8BIM profile, but it seems there is no way to do it programmatically. ImageMagick allows you to get a vector image for example by using the following command:
identify -format "%[8BIM:1999,2998:#1]" test.jpg > test.svg
But it seems not possible to do the reverse operation and add a vector image. Can anyone suggest any libraries which allow this operation?
It's a bit more code than I feel like writing for the moment, but it should be possible to put an 8BIM into a JPEG using the following information.
The anatomy of a JPEG is described here and here.
You can use PIL or OpenCV to encode a JPEG into a memory buffer and then locate and modify/add segments (such as an 8BIM) using code like this. Or you could just read() in an existing JPEG that you want to modify. To insert a segment, just write the first few segments to disk, then write your new one followed by the remaining segments from the existing file that you read at the start.
You can construct an 8BIM segment to insert using this answer.
You can use exiftool -v -v -v to see where an 8BIM appears in a JPEG created by Photoshop and then put yours in a similar place. You can also, obviously, equally use exiftool to see where/how your own attempt has landed.

Is it possible to generate vector based pdf using wordcloud

I am using wordcloud in python to generate word clouds.
I was able to reproduce this example on my machine, and then tried to change the last line plt.show() to plt.savefig('image.pdf') to have a pdf output.
I had a pdf with the same result, however, the pdf seems like pixel-based instead of vector-based. When I focus a particular point in the pdf it becomes a very low-quality picture.
Is there any way to produce vector-based pdf using wordcloud? If not, is there any other library that I can produce vector-based (pdf) wordclouds in Python?
If wordcloud can generate any sort of vector output such as ps or svg, inkscape can usually convert it to a PDF without rasterizing it. You can even do this headless, e.g. inkscape my.svg -A my.pdf.
Hmm, looking at wordcloud, it looks like it uses PIL. I don't think that PIL can produce vector images. But if you could use the logic in wordcloud and separate it from PIL, you can get vector fonts onto PDFs by drawing onto a reportlab canvas.
You can save the images in a vector format so that they will be scalable without quality loss. Such formats are PDF and EPS. Just change the extension to .pdf or .eps and matplotlib will write the correct image format.
plt.savefig('destination_path.eps', format='eps')
plt.savefig('destination_path.pdf', format='pdf')
I have found that eps/pdf files work best.

How to get highest quality .tiff from .pdf using linux software?

I have very picky label printer and need to convert black and white .pdf file to .tiff image saving as much quality as possible. I have an example .tiff converted using some adobe software and that's the quality I am aiming for.
Tried using graphicsmagick for the job, but I just can't get close enough. Here's a section of an image: on the left side is my try and on the right is the one converted with adobe software:
As you can see adobe converted image is much thicker but those images are of same resolution (200x400)
Can somebody give me a hint how to convert .pdf to .tiff using most common python libraries or Ubuntu packages and get similar results?
Cheers

Categories