Use sips command on mac to trim bottom of image

巧了我就是萌 提交于 2019-11-29 17:48:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!