Welcome, guest | Sign In | My Account | Store | Cart
#!/usr/bin/python
# -*- coding: utf-8 -*-
import fitz                    # this is PyMuPDF

'''
Created on Fri Jan 08 17:00:00 2016

@author: Jorj X. McKie

===============================================================================
PyMuPDF demo program
--------------------
Demonstrates some of MuPDF's non-PDF graphic capabilities.

Read a PNG image and create a new one consisting of 3 * 4 tiles of it.
===============================================================================
'''
# read in picture image as a pixmap
pic = open("editra.png", "rb").read()            # read some RGB image into memory
pix0 = fitz.Pixmap(pic, len(pic))                # create a pixel map out of it

# calculate target pixmap dimensions and then create it
tar_width  = pix0.width * 3                      
tar_height = pix0.height * 4
tar_irect  = fitz.IRect(0, 0, tar_width, tar_height)  # we need to define a target rectangle
tar_pix    = fitz.Pixmap(fitz.csRGB, tar_irect)       # now create target RGB pixel map
tar_pix.clearWith(90)        # clear pixmap with a lively gray: (R, G, B) = (90, 90, 90)

# now fill target with 3 * 4 tiles of input picture
for i in list(range(4)):
    pix0.y = i * pix0.height                          # modify input's y coord
    for j in list(range(3)):
        pix0.x = j * pix0.width                       # modify input's x coord
        tar_pix.copyPixmap(pix0, pix0.getIRect())     # copy input to new loc
        # save intermediate images to show what is happening
        fn = "target-" + str(i) + str(j) + ".png"
        tar_pix.writePNG(fn)

Diff to Previous Revision

--- revision 2 2016-03-19 12:38:47
+++ revision 3 2016-03-19 12:40:17
@@ -32,6 +32,6 @@
     for j in list(range(3)):
         pix0.x = j * pix0.width                       # modify input's x coord
         tar_pix.copyPixmap(pix0, pix0.getIRect())     # copy input to new loc
-        # save intermediate image to show what is happening
+        # save intermediate images to show what is happening
         fn = "target-" + str(i) + str(j) + ".png"
         tar_pix.writePNG(fn)

History