diff --git a/src/img2pdf.py b/src/img2pdf.py index 4b222ad..74ebb5e 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -167,6 +167,8 @@ class MyPdfDict(object): class MyPdfName(): def __getattr__(self, name): return b'/' + name.encode('ascii') + + MyPdfName = MyPdfName() @@ -708,7 +710,7 @@ def read_images(rawdata, colorspace, first_frame_only=False): ccittdata = transcode_monochrome(imgdata) imgformat = ImageFormat.CCITTGroup4 result.append((color, ndpi, imgformat, ccittdata, - imgwidthpx, imgheightpx)) + imgwidthpx, imgheightpx)) img_page_count += 1 continue except Exception as e: @@ -1709,5 +1711,6 @@ values set via the --border option. traceback.print_exc(file=sys.stderr) exit(1) + if __name__ == '__main__': main() diff --git a/src/jp2.py b/src/jp2.py index 7f61312..30edb7e 100644 --- a/src/jp2.py +++ b/src/jp2.py @@ -116,6 +116,7 @@ def parsejp2(data): # retrieving the dpi is optional so we do not error out if not present return (width, height, colorspace, hdpi, vdpi) + if __name__ == "__main__": import sys width, height, colorspace = parsejp2(open(sys.argv[1]).read()) diff --git a/src/tests/__init__.py b/src/tests/__init__.py index 6b468aa..506fc48 100644 --- a/src/tests/__init__.py +++ b/src/tests/__init__.py @@ -400,7 +400,7 @@ layout_test_cases = [ def tiff_header_for_ccitt(width, height, img_size, ccitt_group=4): # Quick and dirty TIFF header builder from - # https://stackoverflow.com/questions/2641770/extracting-image-from-pdf-with-ccittfaxdecode-filter + # https://stackoverflow.com/questions/2641770 tiff_header_struct = '<' + '2s' + 'h' + 'l' + 'h' + 'hhll' * 8 + 'h' return struct.pack( tiff_header_struct, @@ -413,7 +413,8 @@ def tiff_header_for_ccitt(width, height, img_size, ccitt_group=4): 258, 3, 1, 1, # BitsPerSample, SHORT, 1, 1 259, 3, 1, ccitt_group, # Compression, SHORT, 1, 4 = CCITT Group 4 262, 3, 1, 1, # Threshholding, SHORT, 1, 0 = WhiteIsZero - 273, 4, 1, struct.calcsize(tiff_header_struct), # StripOffsets, LONG, 1, len of header + 273, 4, 1, struct.calcsize( + tiff_header_struct), # StripOffsets, LONG, 1, len of header 278, 4, 1, height, # RowsPerStrip, LONG, 1, lenght 279, 4, 1, img_size, # StripByteCounts, LONG, 1, size of image 0 # last IFD