MCPcopy Create free account
hub / github.com/PageBot/PageBot / scaleImage

Method scaleImage

Lib/pagebot/contexts/basecontext/basecontext.py:143–168  ·  view source on GitHub ↗

Scales image and stores it to _scaled/image-name.ext. TODO: show optional low resolution marker? Or remove it? TODO: add optional extensions. TODO: move to shared base. TODO: check if index is still necessary.

(self, path, w, h, index=None, showImageLoresMarker=False,
            exportExtension=None, force=False)

Source from the content-addressed store, hash-verified

141 # Image scaling.
142
143 def scaleImage(self, path, w, h, index=None, showImageLoresMarker=False,
144 exportExtension=None, force=False):
145 """Scales image and stores it to _scaled/image-name.ext.
146
147 TODO: show optional low resolution marker? Or remove it?
148 TODO: add optional extensions.
149 TODO: move to shared base.
150 TODO: check if index is still necessary.
151 """
152 assert exists(path)
153 assert self.hasPIL
154 im = Image.open(path)
155 path, ext = self.getResizedPathName(path, w, h)
156
157 if ext == 'jpg':
158 ext = 'jpeg'
159
160 if force or not exists(path):
161 try:
162 im = im.resize((w, h), Image.ANTIALIAS)
163 except OverflowError as e:
164 print('%s: Caught an OverflowError:' % self.name, e)
165 print('Image path is %s' % path)
166 im.save(path, ext)
167
168 return path
169
170 # Older implementation, shows image and optional message.
171 '''

Callers

nothing calls this directly

Calls 3

getResizedPathNameMethod · 0.80
openMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected