Copy Pillow image to GIMP through X11 clipboard - image

I'm using Xubuntu 14.04 (an X11/Linux distribution). I've written a Python program using the Pillow (Python Imaging Library) and Tkinter libraries to render user-entered text into an image using a custom bitmap font. I want to quickly bring this image into the running GIMP process as a new layer. Currently it operates by saving the image to a PNG file and then requiring the user to go dig for the PNG file using GIMP's file picker. I thought it would be more convenient if I could save the image to the X11 clipboard so that I could paste it into GIMP.
But all the examples for interacting with the clipboard in Tkinter that I could find through Google are for text, not images. I found how to copy an image in Windows (1, 2): save a BMP file to a BytesIO, chop off the first 14 bytes, and send the rest to the Windows clipboard as a CF_DIB. But I don't want to require Wine. There also exists an answer about how to do it in GTK+; is it worth porting the application from Tkinter to PyGTK (for GTK+ 2) or PyGObject (for GTK+ 3), despite the installation headache that it may cause for Windows users? Or is there an easier way than the X11 clipboard to get a PIL.Image.Image instance into GIMP?

You can send an image to an open GIMP process by using its "remote" feature. If GIMP is already running, the command gimp path/to/file.png finds GIMP's window and drops the image into the running process. This means you can create a folder with tempfile.TemporaryDirectory, save the image into this folder, and open it in GIMP.
tempfile.TemporaryDirectory is new in Python 3.2 and not available in Python 2. tempfile.NamedTemporaryFile is available in older versions of Python, but the tempfile module docs state that on UNIX, the filename can be passed to another program, but on Windows, the temporary file cannot be opened by other programs while it is open in the program that created it, and once the program that created it closes it, it will already have been deleted. Windows users with both Python 2 and Python 3 installed will need to use Python 3.3 or later in order to let the shebang line processor (PEP 397) select the appropriate version of Python.
Or if you don't want to depend on Python 3.3 or later, you could have your program detect whether it's running on Windows or POSIX and then make the appropriate action available. Under Windows, it would copy the image to the clipboard, and under POSIX, it would write the image to a tempfile.NamedTemporaryFile, pass the filename to gimp or whatever other program the user specifies to receive it, and then destroy the temporary file once a new one is created or the application closes.

Related

Own file extension - behaviour like picture in OS

I'd like to have my own file extension which holds my own data. With double clicking it will start with my own software. So far no problem.
How can i save a picture in that file (metadata?) in a way that it is shown in the OS (Windows, Mac) like a .jpg in the preview window (big symbols in windows, or in the window of the space key preview in macOS)?
The image is generated by my software and therefore is for the user to have a quick info of the internal data...
Thanks in Advance for your help!
Operating systems sometimes allow you to write plugins that read your file data and then convert it to a form that the OS knows how to display in a thumbnail. As for getting your file format to open in existing applications such as Photoshop, this will generally not be possible unless the application developers either choose to add support for your format themselves or allow you to write a plugin, which you will need to do yourself. Most existing file formats that are supported natively in operating systems and user programs have well-known, popular standards and users expect that their software will support these formats by default.

Using applescript / automator to run illustrator batch process

Is there a way to get Automator or Applescript to run 'batch' processes in Adobe Illustrator?
I have a workflow that handles a number of steps - but the key one is to use Illustrator variable data sets to replace two embedded eps files (one of a symbol and one of some text) and a bit of text with a product code.
I'm basically running through this:
http://hypertransitory.com/blog/2014/05/27/use-adobe-illustrator-variable-data-xml/
Except I have some php spitting out the xml that illustrator requires to use for data.
So I have my xml, and if I run a batch process from within illustrator that works fine - trouble is I want to do this multiple times - and each time I want the files to save in the same location. I can get automator to run an action in illustrator, but I can't create an action to load in and run through the data sets from the xml, saving each one. The only way illustrator seems to let you use the variable data sets is via 'batch' - which means you have to provide it with the 'Destination' to export the files to every time (and you can't use it as a step in Automator).
I'm using Illustrator CC (so I believe that's referred to as illustrator 17 in applescript) and OSX 10.10 (if that's relevant)
I'm new to applescript and am busy learning the syntax - but I can't find anything that seems to indicate this is going to be possible!
You can use Illustrator-friendly scripting languages to "manually" change out the datasets within the Illustrator document and output the files into your manually-coded location. If you can find the Applescript commands to do this, you can use it, otherwise you can make a .jsx extendscript and trigger it with your Applescript.
There are also a couple of sets of Illustrator Automator actions, which may be of use to you. Ai Actions and AI Automator Action Pack, both of which are available on the Mac app store. Not as versatile as coding your own bespoke solution using AppleScript (which is how I'd probably approach the problem), but much easier to implement. For the sake of transparency, I'm the developer of the former.

programmatically take screenshot, crop section, and run OCR tools. quick solutions?

I will be writing code that takes a screenshot, crops to a small section of the screen (predefined area of screen), and then extracts the text from that cropped image (via OCR tools), and then saves the resulting text to a file. I was wondering if there is software (preferably for Windows) that can do this, or at least parts of it. I am already looking into tesseract as an OCR tool. Anyone know of software that can take the screenshot, and possibly crop a predefined region of the image.
Thanks,
-Jason
I use Greenshot, which is a very awesome tool for screenshots and according to the FAQ it supports OCR (using MODI = Microsoft Office Document Imaging) as well. However, I never got it working on my Windows machine and used Tesseract instead (for Linux, with some scripting experience, this method should be possible as well):
Download Tesseract here for Ubuntu/Debian/Windows and install it.
Download and install Greenshot
Create a new windows batch script called "Greenshot_Tesseract_OCR.bat" using a text editor like notepad or Notepad++ - and save it at a location of your choice, e.g. "C:\Users\MyUser\Scripts\Greenshot_Tesseract_OCR.bat" - with the following content (depending on the installation location of tesseract):
ECHO OFF
set arg1=%1
"C:\Program Files\Tesseract-OCR\tesseract.exe" "%arg1%" "%arg1%"
type "%arg1%.txt" | clip
Right-click the Greenshot icon in the toolbar and click "configure external command"
Add a new command with a name like "Tesseract OCR to Clipboard", select the batch script you just created as a command and as argument, use the default "{0}". Then click OK twice.
You should now be able to copy the text of a screenshot into your clipboard, with a shortcut ("Print" key in my case) and 1-2 mouse clicks (depending on your Greenshot settings)!
You can try the following open-source programs:
Greenshot for screenshots and VietOCR (a GUI frontend for Tesseract) for OCR on screenshots.

Emacs: Is it possible to browse images in a directory? On Windows?

I read about auto-image-file-mode , which I think displays image files as images within emacs. I'd like to use it. This doc says it has been replaced by image-mode.
I can't get either to work.
Any help?
I got it to work, by downloading the packages for PNG and JPG from GnuWin32, and putting the required DLLs into the \emacs\bin directory:
From LibPng:
libpng-config
libpng12-config
libpng12.dll
libpng3.dll
zlib1.dll
From jpeg:
jpeg62.dll
Now it works. Here's a screen-shot of editing a SO question, being displayed in emacs.
You could also drop those DLLs on the OS's PATH, before running runemacs.exe. That works, too.
It can depend on what version and where you got your windows emacs binary. If you have the windows emacs23 binary from the gnu ftp site then I don't think it is compiled with image support (at least this was the case several months ago). I use the patched windows emacs23 binary from EmacsW32 which does have image support. I also have (auto-image-file-mode) in my .emacs file.
Using Emacs 23.1 (on Fedora 12) when I visit a *.png file, it shows up as an image in the Emacs buffer. Similarly for *.gif and *.pdf files. The mode was advertised as Image[png], fwiw.
Once you've gotten Emacs to show images, you can also see thumbnail images in these contexts, in addition to Dired (using image-dired):
In buffer *Completions* during file-name completion or completion of (file) bookmarks. You need Icicles for this. Showing the thumbnails is optional -- you can toggle it from the minibuffer using C-x t (cycles among: showing only images, images + file names, and only file names).
In buffer *Bookmark List* (from C-x r l), when you hit C-h RET to see info about the current line's bookmark. You need Bookmark+ for this.
bookmarksbookmark

Enable dropping a file onto a Ruby script

I'm creating a small ruby script to resize images and save them in a specified directory. I'd like the application to be as transparent as possible.
Is it possible to allow file dropping onto my Ruby script in all platforms? For instance, the user drags a file onto the script, which then takes the file path as an argument and resizes the image accordingly -- No GUI, no console, etc..
The behavior of drag & drop is dependent on the OS (and in case of Linux of the Window Manager), so no.
In Windows, you get the behavior you want for free. Just put a .rb file on the Desktop, and the files dragged onto it will be arguments to your script.
Another easy way for integrating with Windows is to write to registry entry HKLM\Software\Classes*.jpg\myhandler\command with the command you want to appear in the context menu of Windows Explorer (right click on a jpg file will popup a menu which will have your script in the menu).
I don't use drag & drop at all in Linux, so I wouldn't know how to do that there. I would expect it to have more security issues (permissions must be right, ...) but you could get there by creating a .desktop file, see http://standards.freedesktop.org/desktop-entry-spec/latest/ for the complete standard, or read some examples from ~/Desktop/*.desktop .
Platform dependend, so here for windowsusers and reference only.
Save the following to a .reg file and load it by doublecliking it, tested on Windows Vista and 7
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\rbfile\ShellEx\DropHandler]
#="{86C86720-42A0-1069-A2E8-08002B30309D}"
[HKEY_CLASSES_ROOT\rbwfile\ShellEx\DropHandler]
#="{86C86720-42A0-1069-A2E8-08002B30309D}"
[HKEY_CLASSES_ROOT\RubyFile\ShellEx\DropHandler]
#="{86C86720-42A0-1069-A2E8-08002B30309D}"
[HKEY_CLASSES_ROOT\RubyWFile\ShellEx\DropHandler]
#="{86C86720-42A0-1069-A2E8-08002B30309D}"
Such behavior would surely be platform specific, as drag-and-drop is implemented by the OS in this case, not by ruby.
So answering your question: no, it is not possible.
You can use platypus on os x to create a wrapper around your script.
http://sveinbjorn.org/platypus
regards
Claus

Resources