Created
September 11, 2013 15:11
-
-
Save gabalese/6525015 to your computer and use it in GitHub Desktop.
Basic example of how simple it is to add (slightly) less obvious watermarks to EPUB files with pyepub library and stepic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import os | |
from pyepub import EPUB # see https://github.com/gabalese/pyepub | |
from StringIO import StringIO | |
from PIL import Image | |
import stepic | |
epub = EPUB("startepub.epub","a") | |
epub_images = [x["href"] for x in epub.info["manifest"] if x["mimetype"] == "image/jpeg"] | |
container_img = os.path.join(epub.root_folder, epub_images[0]) | |
flo = StringIO(epub.read(container_img)) | |
epub._delete(container_img) | |
img = Image.open(flo) | |
im2 = stepic.encode(img, 'Hi, this is a plain text string! You can encode me or whatever') | |
flo_out = StringIO() | |
im2.save(flo_out, format="jpeg") | |
epub.writestr(container_img, flo_out.getvalue()) | |
epub.writetodisk("new.epub") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
another method, if interested: https://gist.github.com/broderboy/c2cad83a4855e5454bb3