Creating a multi-page TIFF with Python - python

This has already been asked here, but I was looking for a solution that would work on Linux.. Is tiffcp the only way?

Looks like ImageMagick can do it. The solution is essentially the same; call it from the command line.
Specifically, you want the -adjoin option (which is on by default). The command will look something like:
convert *.tiff my_combined_file.tiff

Haven't tried it, but there is pylibtiff, a python wrapper for the libtiff library on which tiffcp is implemented.

I know this is an old question, but convert has the drawback that it recompresses the images. You can use the python tifftools package to do this without recompressing the images: tifftools merge *.tiff combined_file.tiff.
Disclaimer: I am the author of the tifftools package.

Related

Convert AsciiMath/MathML to SVG/PNG

I'm looking for a way to convert my AsciiMath (or MathML) sources to SVG and/or PNG. I've found a nodeJS library for SVG conversion but calling that from Python is not very convenient and the output is not entirely satisfying.
Taking the fact I'd like to render mathematical formulas to svg/png it seems logical to look for a solution in math libraries (NumPy, SciPy, Pandas, Matplotlib, Sympy, etc...) but to no avail. All my google results combining all possible permutations of asciimath+mathml+svg+png lead to nothing which is strange.
Please recommend me either search patterns to find a solution or share your experiences/ideas to get this seemingly simple job done in Python.
All help would be highly appreciated!
I just created ziamath for exactly this purpose. It comes bundled with the STIX math font, so no setup is required beyond the pip install, but it should also work with other math-enabled fonts. Pure-Python, so it does not need a Latex installation or anything else to work. This first version doesn't quite cover the full MathML specification, but the most useful parts are in there.
To bundle it into an app with something like PyInstaller, you'll need to make sure the STIX font gets included, but that should just be one line in the PyInstaller config.
I have used this for years without issues. It is written in python.
https://sourceforge.net/projects/svgmath/files/svgmath/0.3.3/

Stitching non-R scripts with knitr, say .py

is it possible to stitch a python script using stitch() with knitr?
I want to produce a simple document by typing:
stitch('someScript.py')
analogous to:
stitch('someScript.R')
As I probably have answered you on Twitter, you can try
library(knitr)
opts_chunk$set(engine = 'python')
stitch('script.py')
But note the Python support in knitr is very limited at the moment. You may or may not be satisfied by it.

Python native library to read metadata from videos?

Is there a Python library to read metadata (camera model, time created, etc ...) from video files? The Perl equivalent is "exiftool." I checked pyexiv2, but it doesn't have video support like exiftool does. Thanks.
I have used hachoir-metadata succesfully: http://pypi.python.org/pypi/hachoir-metadata
I have used PyExifTool, a wrapper for the command line program, exif tool. You can get the library here (I think this is the result of the related question in Sven's comment).
The neat thing about PyExifTool is that it also parses the metadata into a dictionary for you.
I used it on a list of file names from os.walk.
import exiftool
exif_Executable="<path to exif executable>"
with exiftool.ExifTool(executable_=exif_Executable) as et:
metadata = et.get_metadata_batch(fileList)

How can I convert PDF pages to images?

I need save PDF pages as images.
Is this possible with pypdf?
As far as I know there is no good way to do this, not with pyPdf or any other libraries I've seen. PIL supports writing, but not reading PDF so it doesn't help here, either. Such support would be quite nice to have. I'd recommend using ImageMagick as a work around, you can call it with subprocess from your script, and have it handle the conversion.
ImageMagick also has Python bindings available, so you could output your images without having to use subprocess

Editing Photoshop PSD text layers programmatically

I have a multi-layered PSD, with one specific layer being non-rasterized text. I'm trying to figure out a way I can, from a bash/perl/python/whatever-else program:
load the PSD
edit the text in said layer
flatten all layers in the image
save as a web-friendly format like PNG or JPG
I immediately thought of ImageMagick, but I don't think I can edit the text layer through IM. If I can accomplish the first two steps some other programmatic way, I can always use ImageMagick to perform the last two steps.
After a couple of hours of googling and searching CPAN and PyPI, I still have found nothing promising. Does anyone have advice or ideas on the subject?
If you don't like to use the officially supported AppleScript, JavaScript, or VBScript, then there is also the possibility to do it in Python. This is explained in the article Photoshop scripting with Python, which relies on Photoshop's COM interface.
I have not tried it, so in case it does not work for you:
If your text is preserved after conversion to SVG then you can simply replace it by whatever tool you like. Afterwards, convert it to PNG (eg. by inkscape --export-png=...).
The only way I can think of to automate the changing of text inside of a PSD would be to use a regex based substitution.
Create a very simple picture in Photoshop, perhaps a white background and a text layer, with the text being a known length.
Search the file for your text, and with a hex editor, search nearby for the length of the text (which may or may not be part of the file format).
Try changing the text, first to a string of the same length, then to something shorter/longer.
Open in Photoshop after each change to see if the file is corrupt.
This method, if viable, will only work if the layer in question contains a known string, which can be substituted for your other value. Note that I have no idea whether this will work, as I don't have Photoshop on this computer to try this method out. Perhaps you can make it work?
As for converting to png, I am at a loss. If the replacing script is in Python, you may be able to do it with the Python Imaging Library (PIL, which seems to support it), but otherwise you may just have to open Photoshop to do the conversion. Which means that it probably wouldn't be worth it to change the text pragmatically in the first place.
Have you considered opening and editing the image in The GIMP? It has very good PSD support, and can be scripted in several languages.
Which one you use depends in part on your platform, the Perl interface didn't work on Windows the last I knew. I believe Scheme is supported in all ports.
You can use Photoshop itself to do this with OLE. You will need to install Photoshop, of course. Win32::OLE in Perl or similar module in Python. See http://www.adobe.com/devnet/photoshop/pdfs/PhotoshopScriptingGuide.pdf
If you're going to automate Photoshop, you pretty much have to use Photoshop's own scripting systems. I don't think there's a way around that.
Looking at the problem a different way, can you export from Photoshop to some other format which supports layers, like PNG, which is editable by ImageMagick?
You can also try this using Node.js. I made a PSD command-line tool
One-line command install (needs NodeJS/NPM installed)
npm install -g psd-cli
You can then use it by typing in your terminal
psd myfile.psd -t
You can check out the code to use it from another node script or use it through your shell is from another Bash/Perl/whatever script.

Categories

Resources