There is no way to do what you need with a standard Automator step.
Anyway, you can use this Python script:
import sys
import CoreGraphics
RESIZE_WIDTH = 100
RESIZE_HEIGHT = 100
def resizeimage(source_image_file, target_image_file, target_width, target_height):
source_image = CoreGraphics.CGImageImport(CoreGraphics.CGDataProviderCreateWithFilename(source_image_file))
source_width = source_image.getWidth()
source_height = source_image.getHeight()
source_image_rect = CoreGraphics.CGRectMake(0, 0, source_width, source_height)
new_image = source_image.createWithImageInRect(source_image_rect)
colors_space = CoreGraphics.CGColorSpaceCreateDeviceRGB()
colors = CoreGraphics.CGFloatArray(5)
context = CoreGraphics.CGBitmapContextCreateWithColor(target_width, target_height, colors_space, colors)
context.setInterpolationQuality(CoreGraphics.kCGInterpolationHigh)
new_image_rect = CoreGraphics.CGRectMake(0, 0, target_width, target_height)
context.drawImage(new_image_rect, new_image)
context.writeToFile(target_image_file, CoreGraphics.kCGImageFormatJPEG)
def main(argv):
for image_file_name in argv:
resizeimage(image_file_name, image_file_name, RESIZE_WIDTH, RESIZE_HEIGHT)
if __name__ == "__main__":
main(sys.argv[1:])
Set RESIZE_WIDTH
and RESIZE_HEIGHT
to whichever value you need.
Add it as a Run Shell Script
step:
and set Shell
to /use/bin/python
and Pass input
to as arguments
.
EDIT: there's a rather simpler way (suggested by epatel) to achieve this, using sips
.
You can create a Run Shell Script
step with this command:
sips --resampleHeightWidth 100 100 "$@"
Note: Double Quotes need to surround $@ or you will get an error.