Crop image
Moderators: XnTriq, helmut, xnview
Crop image
How to set the correct command in order to crop the image to the specified size. Do not squeeze
?
?
Re: Crop image
Code: Select all
-crop x y w h : Crop
Code: Select all
-canvas w h pos : Resize canvas
w h can be percent (ex: -canvas 100% 200%)
or #x #y for offset
pos top-left, top-center, top-right
center-left, center, center-right
bottom-left, bottom-center, bottom-right
Re: Crop image
Code: Select all
nconvert -ratio -resize shortest 180 -overwrite %title_alt%.jpg
nconvert -ratio -canvas 50 100 -overwrite %title_alt%.jpg
Re: Crop image
Zuldek wrote: ↑Sat Jul 06, 2019 3:49 pmDoes not go, the image size remains the sameCode: Select all
nconvert -ratio -resize shortest 180 -overwrite %title_alt%.jpg nconvert -ratio -canvas 50 100 -overwrite %title_alt%.jpg
Could you please explain in more detail what you wish to do, you wish to reduce the pixel dimensions of the input image %title_alt%.jpg ?
By cropping, or resizing the pixel dimensions without cropping?
Are you able to upload an example input image?
Re: Crop image
Reduce the canvas, that is, size the image. Parts of the image that do not fit the size, they are cut off.
- Attachments
-
- dff.jpg (9.81 KiB) Viewed 3305 times
Re: Crop image
Reduce the width of the image, equally about the center??
Otherwise, could you draw on the image to indicate which part to wish to keep, or explain in more detail what you need?
Re: Crop image
A width of 200 is required, a height of 100. If possible, yes, in the center.
Re: Crop image
I think that's clear, I'll try to test the code required later, please be patient...
Re: Crop image
This is the basic code to produce the image you need as I understand it, you may wish to edit the exact values used:
Code: Select all
nconvert -canvas 200 100 center dff.jpg
The following code can be used to change the name of the output file, if desired, and also add compression to the output JPEG, 70% here:
Code: Select all
nconvert -canvas 200 100 center -o Output.jpg -out jpeg -q 70 Input.jpg
For reference, the following is the help file listing for the -canvas option:
Code: Select all
-canvas w h pos : Resize canvas
w h can be percent (ex: -canvas 100% 200%)
or #x #y for offset
pos top-left, top-center, top-right
center-left, center, center-right
bottom-left, bottom-center, bottom-right
Edit:
If your need is actually to display the whole image vertically, rescaled to a height of 100 pixels, and to crop the width to 200 pixels without distorting the image, perhaps you could test the following options which I have never had a reason to use:
Code: Select all
-resize longest size : Scale longest side
-resize shortest size : Scale shortest side
Re: Crop image
Code: Select all
nconvert -ratio -resize shortest 180 -o titlee.jpg -q 70 scrinshot.jpg
nconvert -canvas 320 180 center -o titlee.jpg -q 70 titlee.jpg
The second stage is cropping the image.
I don’t quite understand how to save the image with the same output name in the second stage. So that no titlee_1.jpg titlee_2.jpg
Re: Crop image
You seem to have made some progress, but it is sometimes difficult to understand what you wish to do...Zuldek wrote: ↑Sun Jul 07, 2019 10:51 amThe first stage is image compression.Code: Select all
nconvert -ratio -resize shortest 180 -o titlee.jpg -q 70 scrinshot.jpg nconvert -canvas 320 180 center -o titlee.jpg -q 70 titlee.jpg
The second stage is cropping the image.
Also NConvert has many options and I haven't used them all myself: I see the use of the -ratio option which was needed to avoid distorting the input image when resizing it, and I see that the -q option can be used without the -out option.
You wish the output from the second stage to have the name 'titlee.jpg' and it doesn't? I suspect the problem arises from the fact that when a file of the same name already exists in the same folder, the output file is given a suffix -1, -2 etc.I don’t quite understand how to save the image with the same output name in the second stage. So that no titlee_1.jpg titlee_2.jpg
If that is the problem, I see two possible solutions: one would be to use the -D option to delete the input file, if that is acceptable, the second is to use the appropriate -o option:
Code: Select all
-o filename : Output filename
Use # to specify position of numeric enumerator
Use % to specify source filename
Use $ to specify full source pathname
Use $$ to specify source folder name
Use $EXIF:DateModified[date format] to specify EXIF date modified
Use $EXIF:DateTaken[date format] to specify EXIF date taken
Date format: Please check documentation of strftime