Sunday, October 6, 2013

Extracting text from Photoshop (PSD) images

I just needed to grab text from some Photoshop images and put it into a LaTeX document. But, how do I get that text on Linux? GIMP can't do it, nor can any other program I tried (they all rasterize the text). Fortunately the text is just saved in plain in the .psd file, so it's relatively easy to get it out of there. However it's in utf-16, so with just grep it's quite painful. Here's a little Python script which finds and decodes text from psd images (inline version below). You use it by passing it the .psd file, and the beginning of the text you want to find, and it'll give you the rest.
python psdtextextract.py myimage.psd "This is"
will result in "This is a text layer." if that's the text your layer indeed contains. To find a sample of the text you can use any image viewer such as gwenview. Quite stupid, I know, but it works ;)

Inline source code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from codecs import encode, decode

def get_next_occurence(text, buf, start):
    text = encode(text, "utf-16")[2:] # cut BOM
    index = buf.find(text, start)
    if index == -1:
        return b"", -1
    end = buf.find(b'\x00\x00', index)
    if end == -1:
        return b"", -1
    chunk = b'\x00' + buf[index:end + 2]
    return chunk.replace(b'\x5C', b''), end

def get_all_occurences(text, buf):
    start = 0
    items = []
    while start != -1:
        try:
            found, start = get_next_occurence(text, buf, start)
            items.append(decode(found, "utf-16be").replace('\r', '\n'))
        except UnicodeDecodeError as e:
            continue
            print(" - undecodable match skipped:", e)

    return items

if __name__ == '__main__':
    import sys
    if len(sys.argv) > 4 or len(sys.argv) < 3:
        print("Usage: psdtextextract.py file.psd pattern [display-all-matches]")
    with open(sys.argv[1], 'rb') as f:
        items = get_all_occurences(sys.argv[2], f.read())
        if "display-all-matches" not in sys.argv:
            print(items[0])
        else:
            for item in items:
                print(item)

Tuesday, September 24, 2013

Collaborative text editing: 0.2 beta release and end of GSoC

After three months and 430 commits introducing 23165 changes (line insertions/removals; in the kte-collaborative repository, plus about 50 more commits in kde-telepathy and libqinfinity), the beta release I hereby announce marks the end of my Google Summer of Code project, which consisted of implementing collaborative text editing in KTextEditor (see previous).

For more general information about the project, make sure to also have a look at the user manual, which has some in-depth explanations on how things work.

First, the technical stuff:
libqinfinity version 0.5.1:
http://download.kde.org/stable/libqinfinity/0.5.1/src/libqinfinity-v0.5.1.tar.xz.mirrorlist
SHA256: bcfeb899921057cf4e7f393c48ca6b4f7e3ee21c64c783f692a5af48118755ad

kte-collaborative version 0.1.80 (aka 0.2 beta 1):
http://download.kde.org/unstable/kte-collaborative/0.1.80/src/kte-collaborative-v0.1.80.tar.xz.mirrorlist 
SHA256: 2679611900796be86af8fc84a5f90bb76fedff715f29d4530ed5ccf982c3fe03

kte-collaborative depends on kde-telepathy 0.7 beta or later.
Now, read on for the more interesting things!

Sunday, August 25, 2013

Collaborative text editing in KTextEditor and kde-telepathy: Preview release

We have decided that kte-collaborative (the "Collaborative text editing in KTextEditor via kde-telepathy" project -- see previous) is ready for a first release! This release is explicitly flagged as "preview" and might not be suitable for daily use just yet. There are still some known problems; the release is meant as an invitation to curious users to test the program and tell us about any problems they encounter.

Release tarballs:
You might want to use the heads of the 0.5 and 0.1 git branches of libqinfinity and kte-collaborative instead to profit from the latest fixes made after the release tagging.

Saturday, August 17, 2013

GSoC: Collaborative text editing in Kate + kde-telepathy: status report No. 3

Read my first status report for a more general introduction on what is happening. The second report gives some information about features implemented earlier.

Much has happened in the "bring collaborative text editing to kate and kde-telepathy" project! This blog post will outline some of the most important changes, such as undo support and sharing documents with chatrooms.
Current snapshot of kte-collaborative

Monday, July 8, 2013

GSoC: Collaborative text editing in Kate + kde-telepathy: status report No. 2

Read my first status report for a more general introduction on what is happening.

In the last two weeks, I have implemented many shiny new things in kte-collaborative! Here's a short summary of the most prominent ones.




Monday, June 24, 2013

GSoC: Collaborative text editing in kate + kde-telepathy

First of all, I've been accepted for GSoC this year! I'll be working on creating a collaborative text editor based on the KTextEditor interface and libinfinity library, and on integrating that editor into kde-telepathy. The point of integration with kde-telepathy is that it will allow for a nice user experience in setting up connections: instead of typing IP addresses, they can just select a person from their contact list.
"Integration" doesn't mean you'll be required to use it, though -- it'll work just fine with the old-fashioned way, too.
This post will give a rough overview over the project and what I have done so far.
First, here's a nice image so you don't get bored.
Collaborative editing in kate.

Saturday, May 18, 2013

kdev-python 1.5.1 released

kdev-python provides Python language support for the KDevelop integrated development environment. For more information, please look at the 1.4 and 1.5 release announcements, and especially make sure to watch this short demonstration video!

The 1.5.1 release fixes a few issues with 1.5.0. Especially, it
  • fixes a crash bug which could happen when PEP8 checking was enabled
  • fixes capitalization in the coding line completion
  • displays the correct plugin version in the About dialog
This is a rather minor update and I recommend it to everyone running 1.5.

There's one thing I forgot to announce in the 1.5 release: PEP8 checking support (which was actually a good thing, since it was rather crashy until now ;)).
PEP8 checking suppot in kdev-python 1.5.1
It will run the PEP8 style checker whenever an open file is modified and display all errors inline (if you have inline error display enabled) and in the Problems toolview.
By default it is disabled though, since it displays a lot of errors for people who don't follow PEP8, so if you want to use it, go to Settings -- Configure KDevelop -- PEP8 style checking (the change will only apply to newly opened or modified files).

If there's any issues, please make sure to let me know on the bug tracker.

The tarball can be found here, sha256 checksum is  d9b68bd2dd9361961e264254d2acfebc9ce0ea4b47ea2689d2f01a3ed81f7c47