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
Related
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.
I am using OpenCV Python to read in images. I read them in as grayscale as reading in the full colour image is expensive. However, I still need to identify the number of colour channels in the original image.
Is there a simple method of extracting the number of colour channels in an image using EXIF tags, PIL or any other libraries without reading in the full colour image?
imagemagick: $ magick identify -ping <file> reads as little as possible of a file and dumps a few basic properties of the picture file. discussion: https://legacy.imagemagick.org/discourse-server/viewtopic.php?t=18042
you can run and read that using python's subprocess module. check_output() is probably most useful here.
I've just tried that on a 5 GB TIFF file and it runs in no time at all.
you will have to interpret that line somewhat. it says here "8-bit sRGB", which would imply three channels. sRGB is an RGB color space.
you can pass -format ... and a format string to get custom output.
imagemagick has a command line interface but I hear it also has APIs you can call from python. other answer with details on that: Can I access ImageMagick API with Python?
if that's unsuitable you will need to use specific libraries (libjpeg, libpng, libtiff, ...)
I have a BMP image and I want to extract a small portion of it and save it as a new BMP image file.
I was able to load image and read it however I was not able to extract the small portion of BMP image as I am new to manipulating BMP image with python and also it not same as reading text file.
Things I have to do is
load image.
extract small portion of image.
eg. I have to extract 40X40 pixel image from 900X900 image file
then save extracted image as new file. eg new.bmp
I am trying to do this for last 3 days also I have searched a lot in the net but got solution which uses Pillow library however I need it to do this without using any external module of Python. Stackoverflow is my last hope I need some guidance from a expert people present here, please provide my some guidance.
I am using a python program to produce some data, plotting the data using matplotlib.pyplot and then displaying the figure in a latex file.
I am currently saving the figure as a .png file but the image quality isn't great. I've tried changing the DPI in matplotlib.pyplot.figure(dpi=200) etc but this seems to make little difference. I've also tried using differnet image formats but they all look a little faded and not very sharp.
Has anyone else had this problem?
Any help would be much appreciated
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. Remember LaTeX likes EPS and PDFLaTeX likes PDF images. Although most modern LaTeX executables are PDFLaTeX in disguise and convert EPS files on the fly (same effect as if you included the epstopdf package in your preamble, which may not perform as well as you'd like).
Alternatively, increase the DPI, a lot. These are the numbers you should keep in mind:
300dpi: plain paper prints
600dpi: professional paper prints. Most commercial office printers reach this in their output.
1200dpi: professional poster/brochure grade quality.
I use these to adapt the quality of PNG figures in conjunction with figure's figsize option, which allows for correctly scaled text and graphics as you improve the quality through dpi.
When resizing images along the lines shown in this question occasionally the resulting image is inverted. About 1% of the images I resize are inverted, the rest is fine. So far I was unable to find out what is different about these images.
See resized example and original image for examples.
Any suggestions on how to track down that problem?
I was finally able to find someone experienced in JPEG and with some additional knowledge was able to find a solution.
JPEG is a very underspecified
Format.
The second image is a valid JPEG but it is in CMYK color space, not in RGB color space.
Design minded tools (read: things from Apple) can process CMYK JPEGs, other stuff (Firefox, IE) can't.
CMYK JPEG is very under specified and the way Adobe Photoshop writes it to disk is borderline to buggy.
Best of it all there is a patch to fix the issue.
Your original image won't display for me; Firefox says
The image “http://images.hudora.de/o/NIRV2MRR3XJGR52JATL6BOVMQMFSV54I01.jpeg”
cannot be displayed, because it contains errors.
This suggests that the problem arises when you attempt to resize a corrupted JPEG, and indeed your resized example shows what looks like JPEG corruption to my eye (Ever cracked open a JPEG image and twiddled a few bits to see what it does to the output? I have, and a few of my abominable creations looked like that). There are a few JPEG repair tools out there, but I've never seriously tried any of them and don't know if they might be able to help you out.