You can try PyTurboJPEG , which is a Python libjpeg-turbo shell with insanely fast scaling (1/2, 1/4, 1/8) when decoding a large JPEG image, as shown below,
import pygame from turbojpeg import TurboJPEG # specifying library path explicitly # jpeg = TurboJPEG(r'D:\turbojpeg.dll') # jpeg = TurboJPEG('/usr/lib64/libturbojpeg.so') # jpeg = TurboJPEG('/usr/local/lib/libturbojpeg.dylib') # using default library installation jpeg = TurboJPEG() # direct rescaling 1/2 while decoding input.jpg to RGBA pixel array pixel_array = jpeg.decode( open('input.jpg', 'rb').read(), pixel_format=TJPF_RGBA, scaling_factor=(1, 2)) height, width, _ = pixel_array.shape image = pygame.image.frombuffer(pixel_array.data, (width, height), 'RGBA')
libjpeg-turbo prebuilt binaries for macOS and Windows 7 are also available here .
Lilo huang
source share