Answer the question
In order to leave comments, you need to log in
Is there a batch image processing program that can convert a rectangular photo into a square one and center it?
Good afternoon.
There are 2-5 GB of images. The most different.
Required:
1. Reduce to the desired square size.
2. Center.
Images should not become distorted.
Answer the question
In order to leave comments, you need to log in
I've always done this in Photoshop.
1) Open one picture
2) Click on REC in the action box
3) Resize the open picture and press stop
4) Somewhere in the File menu, find the Batch command, in the window that opens, select the action that you recorded, and the folder where your pictures are located .
The beauty is that when recording an action, you can add any number of actions on images, for example, auto contrast, auto-leveling, adding copyright, frames, filters, etc.
Another option in Photoshop, from some versions, such a thing appeared File> Scripts> Image Processor - it's just a resize of the images folder
Maybe I'm confusing something, but how can you make a square out of a rectangular one without distortion? If only cut. If this is your case, then here is XnView . There is batch processing of files, everything is simple, visual, fast and free.
Lazarus ( www.lazarus.freepascal.org/index.php ) in hand, the final picture on the form, take the original one, process it with this procedure. The meaning, I think, is clear. If you need - I can lay out all the sources.
Procedure TForm1.StretchFine(inPicture: TPicture; OutImage: TImage);
Var A, B, X, Y, X1, Y1, DX, DY: integer;
r1, r2 : real;
StretchFineImage : TImage;
Begin
A := OutImage.width;
B := OutImage.height;
StretchFineImage := TImage.Create(Nil);
StretchFineImage.width := a;
StretchFineImage.height := b;
StretchFineImage.left := 0;
StretchFineImage.Top := 0;
X := InPicture.width;
Y := InPicture.height;
R1 := X / Y; //соотношение в исходной картинке
R2 := A / B; // -- в итоговой картинке
If r1 > r2 Then Begin
x1 := A;
y1 := trunc(A / X * Y);
End Else Begin
x1 := trunc(B / Y * X);
y1 := b;
End;
Dx := trunc((a - x1) / 2);
Dy := trunc((b - y1) / 2);
StretchFineImage.Canvas.Brush.Color := clWhite;
StretchFineImage.Canvas.FillRect(rect(0, 0, a, b));
StretchFineImage.Canvas.StretchDraw(rect(Dx, Dy, a - Dx, b - Dy), InPicture.Graphic);
OutImage.Picture := StretchFineImage.Picture;
StretchFineImage.Free;
StretchFineImage := Nil;
End;
There are several ways to turn a rectangular image into a square one:
- Crop the edges of the image to a square
- Add black / white margins to a square
- Stretch disproportionately
- Using the liquid rescale / seam carving algorithm
In any case (except for the second one), the image will be distorted. See www.imagemagick.org/Usage/resize
for more details on how to resize
. And of course ImageMagick will help you with any scenario.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question