Page 1 of 1

Crop image

Posted: Fri Jul 05, 2019 4:29 pm
by Zuldek
How to set the correct command in order to crop the image to the specified size. Do not squeeze

?

Re: Crop image

Posted: Fri Jul 05, 2019 5:09 pm
by cday
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
Also the following option may be considered a 'crop' function:

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
Note that the second post in this thread shows how to create a copy of the help file for the version you are using. :D

Re: Crop image

Posted: Sat Jul 06, 2019 3:49 pm
by Zuldek

Code: Select all

    nconvert -ratio -resize shortest 180 -overwrite %title_alt%.jpg
	nconvert -ratio -canvas 50 100 -overwrite %title_alt%.jpg
Does not go, the image size remains the same

Re: Crop image

Posted: Sat Jul 06, 2019 4:06 pm
by cday
Zuldek wrote:
Sat Jul 06, 2019 3:49 pm

Code: Select all

    nconvert -ratio -resize shortest 180 -overwrite %title_alt%.jpg
	nconvert -ratio -canvas 50 100 -overwrite %title_alt%.jpg
Does not go, the image size remains the same

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

Posted: Sat Jul 06, 2019 4:46 pm
by Zuldek
Reduce the canvas, that is, size the image. Parts of the image that do not fit the size, they are cut off.

Re: Crop image

Posted: Sat Jul 06, 2019 4:52 pm
by cday
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.
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

Posted: Sat Jul 06, 2019 5:12 pm
by Zuldek
A width of 200 is required, a height of 100. If possible, yes, in the center.

Re: Crop image

Posted: Sat Jul 06, 2019 5:17 pm
by cday
I think that's clear, I'll try to test the code required later, please be patient...

Re: Crop image

Posted: Sat Jul 06, 2019 6:48 pm
by cday
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

Re: Crop image

Posted: Sun Jul 07, 2019 10:51 am
by Zuldek

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 first stage is image compression.
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

Posted: Sun Jul 07, 2019 11:55 am
by cday
Zuldek wrote:
Sun Jul 07, 2019 10:51 am

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 first stage is image compression.
The second stage is cropping the image.
You seem to have made some progress, but it is sometimes difficult to understand what you wish to do... :wink:

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.

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
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.

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
In this case -o %.jpg should work, I think without testing that, but note that in a batch file .bat the % symbol must be doubled to 'escape' the character, so -o %%.jpg.