Page MenuHomePhabricator
Paste P2540

jpeg:size in wand
ActivePublic

Authored by Gilles on Jan 28 2016, 11:27 PM.
Tags
None
Referenced Files
F3289426: jpeg:size in wand
Feb 24 2016, 5:27 AM
Subscribers
None
import os, resource, sys
import wand.image as image
image.OPTIONS = frozenset(['fill', 'jpeg:sampling-factor', 'pdf:use-cropbox', 'jpeg:size'])
def utime():
return resource.getrusage(resource.RUSAGE_SELF).ru_utime
+ resource.getrusage(resource.RUSAGE_CHILDREN).ru_utime
size = 98, 72
for infile in sys.argv[1:]:
outfile = os.path.splitext(infile)[0] + ".thumbnail.jpg"
if infile != outfile:
try:
with image.Image() as im:
im.options['jpeg:size'] = '98x72'
im.read(filename=infile)
start = utime()
im.resize(98, 72)
duration = utime() - start
duration = int(round(duration * 1000, 0))
print "Utime: %r" % duration
im.save(filename=outfile)
except IOError:
print "cannot create thumbnail for '%s'" % infile