I have a set of images, all of which have quite different resolutions from each other. I want to first crop them in the ratio 2:1 and then resize them to 1000x500 so that the image is not stretched or distorted in any way. I used different image resizer programs to do it but I am able to process only a few images at a time whose lengths are approximately equal. I want a software or a piece of PHP or Java code to process all of the images at once and crop them all in the ratio 2:1 in the center. Any help would be greatly appreciated as I need this often.
\$\begingroup\$
\$\endgroup\$
6
-
3\$\begingroup\$ Just to confirm: if you had a 4000x4000 image, you would want to first crop it to 4000x2000 (how do you choose where to crop - centre of the image?) and then resize that to 1000x500? \$\endgroup\$– Philip Kendall ♦Commented Nov 22, 2021 at 17:26
-
\$\begingroup\$ GraphicConverter can do all that. \$\endgroup\$– TetsujinCommented Nov 22, 2021 at 18:17
-
\$\begingroup\$ @PhilipKendall, Yes, you got it right. I mean exactly that. \$\endgroup\$– Asmat AliCommented Nov 22, 2021 at 18:38
-
1\$\begingroup\$ This is a nice little programming project. Since you mention PHP and Java, why don't you just write your own piece of software? \$\endgroup\$– osullicCommented Nov 22, 2021 at 22:40
-
2\$\begingroup\$ The canonical answer to this is to use ImageMagick in a shell script (IM also has PHP and Java bindings, if necessary). \$\endgroup\$– xenoidCommented Nov 23, 2021 at 9:40
|
Show 1 more comment
1 Answer
\$\begingroup\$
\$\endgroup\$
PHP has the imagecrop and imagescale functions, so it should be trivial to cobble together a loop to process a batch of files.