Home > Blockchain >  Convert PG file contains many images
Convert PG file contains many images

Time:11-02

I have a pg file when I open it in Windows 7 I notice that it contains many images in one file.

Currently using python I'm trying to count the number of images inside this file or extract them but I can't find anything about pg files.

When I used an online converter, all the images were extracted and uploaded to a ZIP file I'm trying to use the same thing but using Python but only get one image.

Note: I used the pillow library (there is only one file 1.pg for example)

from PIL import Image

img = Image.open('1.pg')
rgb_img = img.convert('RGB')
rgb_img.save('image.jpg')

CodePudding user response:

PG is not in the list of supported image formats, I'm surprised you can open it at all. If it supports multiple images per file, that support might be the same as provided for TIFF images using the seek function.

CodePudding user response:

Your file is a multi-page TIFF with 9 sub-images, created by OPENTEXT CORPORATION. You may be able to seek/iterate over them with PIL per Mark Ransom's suggestion. The example is here.

If not, you can extract them with ImageMagick in the Terminal with:

magick YOURFILE.PG page-%d.jpg

Change .jpg to .png or any other image type you prefer.

Replace magick with convert if using old, v6 ImageMagick.


You can see an overview of the contents like this:

magick identify 1.pg
1.pg[0] TIFF 3471x2480 3471x2480 0 0 1-bit Bilevel Gray 730979B 0.010u 0:00.001
1.pg[1] TIFF 3468x2480 3468x2480 0 0 1-bit Bilevel Gray 0.010u 0:00.001
1.pg[2] TIFF 3464x2488 3464x2488 0 0 1-bit Bilevel Gray 0.010u 0:00.000
1.pg[3] TIFF 3471x2488 3471x2488 0 0 1-bit Bilevel Gray 0.010u 0:00.000
1.pg[4] TIFF 3473x2480 3473x2480 0 0 1-bit Bilevel Gray 0.000u 0:00.000
1.pg[5] TIFF 3473x2480 3473x2480 0 0 1-bit Bilevel Gray 0.000u 0:00.000
1.pg[6] TIFF 3465x2472 3465x2472 0 0 1-bit Bilevel Gray 0.000u 0:00.000
1.pg[7] TIFF 3463x2472 3463x2472 0 0 1-bit Bilevel Gray 0.000u 0:00.000
1.pg[8] TIFF 3469x2472 3469x2472 0 0 1-bit Bilevel Gray 0.000u 0:00.000

You may find you can get better results from some programs by simply creating a copy of your file called 1.tif because Windows is over-reliant on file extensions to determine file content/type whereas Linux, Unix and macOS are smarter.

  • Related