Crop image
Moderators: XnTriq, helmut, xnview
-
- Posts: 12
- Joined: Fri Jul 05, 2019 1:24 pm
Crop image
How to set the correct command in order to crop the image to the specified size. Do not squeeze
?
?
-
- XnThusiast
- Posts: 4300
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: Crop image
Zuldek wrote: Fri Jul 05, 2019 4:29 pm How to set the correct command in order to crop the image to the specified size. Do not squeeze
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

-
- Posts: 12
- Joined: Fri Jul 05, 2019 1:24 pm
Re: Crop image
Code: Select all
nconvert -ratio -resize shortest 180 -overwrite %title_alt%.jpg
nconvert -ratio -canvas 50 100 -overwrite %title_alt%.jpg
-
- XnThusiast
- Posts: 4300
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
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?
-
- Posts: 12
- Joined: Fri Jul 05, 2019 1:24 pm
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.
You do not have the required permissions to view the files attached to this post.
-
- XnThusiast
- Posts: 4300
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: Crop image
Reduce the width of the image, equally about the center??Zuldek wrote: Sat Jul 06, 2019 4:46 pm Reduce the canvas, that is, size the image. Parts of the image that do not fit the size, they are cut off.
Otherwise, could you draw on the image to indicate which part to wish to keep, or explain in more detail what you need?
-
- Posts: 12
- Joined: Fri Jul 05, 2019 1:24 pm
Re: Crop image
A width of 200 is required, a height of 100. If possible, yes, in the center.
-
- XnThusiast
- Posts: 4300
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: Crop image
I think that's clear, I'll try to test the code required later, please be patient...
-
- XnThusiast
- Posts: 4300
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: Crop image
Zuldek wrote: Sat Jul 06, 2019 5:12 pm A width of 200 is required, a height of 100. If possible, yes, in the center.
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
-
- Posts: 12
- Joined: Fri Jul 05, 2019 1:24 pm
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
-
- XnThusiast
- Posts: 4300
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
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