问题
I want to write a batch command script for osx that will crop off the bottom of an image. Is that possible using sips?
I have a bunch of images 640 x 1136 and I want crop them (not scale or resize) to 640 x 960. When the image is cropped, I want the bottom of the image removed and the top to stay the same. Basically, I just want to cut the bottom of the image off.
I have this but it's cropping both from the top of the image and bottom.
sips --cropToHeightWidth 640 960
回答1:
Doesn't look like it's possible. Thanks guys.
回答2:
It's only taken me 2 years to think this up... but you can do it with the GD library which is actually included in the standard, built-in OSX PHP interpreter (so no need to install any packages):
#!/usr/bin/php -f
<?php
$im = imagecreatefromjpeg("image.jpg");
$crop_area = array('x'=>0,'y'=> 0,'width'=>640,'height'=>960);
$result = imagecrop($im, $crop_area);
imagejpeg($result,"result.jpg");
?>
To call from Terminal, you would save it in a file, called say chopper
and then make the file executable like this:
chmod +x chopper
and then you could run it by typing:
./chopper
or double-clicking it in Finder.
I guess you would want to make it take parameters of the filename to open and the filename to save and the dimensions, but you get the idea.
回答3:
You could also use the flip mode twice.
sips --flip vertical image.jpg
sips --cropToHeightWidth 640 960
sips --flip vertical image.jpg
This has done it for me.
Update
Like the comments says this solution does not work any longer. Sorry for that.
来源:https://stackoverflow.com/questions/19867726/use-sips-command-on-mac-to-trim-bottom-of-image