I've been searching for about an hour now to try and find a way to do this.
Is there any way in Automator to resize images to a specified width and height, instead of just the longest size? I need my output images to be a specific pixel width and height, even if it is disproportionate.
I have photoshop, so is there a way to get Automator to do this?
Thanks
Now anytime you want to resize an image, all you need to do is right-click on it, hover over Quick Actions, and select Image Resize if that's what you name this action or whatever name you named it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With