Page 1 of 1

Convert to specific cm +DPI + add canvas to top

Posted: Wed Dec 04, 2019 3:17 pm
by 4dshopper
Hi all,
im new and i have a question:

I would like to convert a scr image to a sepcific cm dimension+dpi+add canvas

i found some comments and the following command line works fine for me.
But i need to know how i can set a cm dimension - not px dimension:
nconvert -out png -ratio -resize 0 1024 -dpi 150 tmp_bottle.png

Can anyone explain me, what "-out" does mean?

i would do something like this:

nconvert -out png -ratio -resize 0 25cm -dpi 150 tmp_bottle.png

Image

Kind Regards
Markus

Re: Convert to specific cm +DPI + add canvas to top

Posted: Wed Dec 04, 2019 5:43 pm
by cday
4dshopper wrote: Wed Dec 04, 2019 3:17 pm Can anyone explain me, what "-out" does mean?

Code: Select all

 -out format       : Output format name
So -out specifies the format of the output file, but when the output format is to be the same as the input file format, it can normally be omitted, I think.

When -out is used it can be followed by a -c term that specifies the type of compression to be used, although I don't see any compression options for the PNG format.

I need to know how I can set a cm dimension - not px dimension:

nconvert -out png -ratio -resize 0 1024 -dpi 150 tmp_bottle.png

Code: Select all

-resize w h      : Scale width-height
     w h can be percent (ex: -resize 100% 200%)
The -resize output dimensions can only be specified in pixels or as a percentage of the input dimensions as far as I know, however the size in cm can be calculated from the pixel dimensions and dpi values used: cm = px x dpi . You therefore need to calculate the pixel dimensions that correspond to the dpi value you are using.

Have you made a copy of the NConvert help file you can create using -help at the command prompt?

Re: Convert to specific cm +DPI + add canvas to top

Posted: Thu Dec 05, 2019 8:27 am
by 4dshopper
@cday Thank you for you specific answer!

It help me to understand what i have to do.
Yes i have made a copy of -help > help.txt

That what i have to do know:

Calculate how many pixel has one cm in 150 DPI.
Image

I think that should be right?
-if i need a height of 23 cm (23x59px) =1357 px

nconvert -ratio -resize 0 1357 -dpi 150 tmp_bottle.png - That should be fine if i have input png and need a 23cm Height.

And for add a canvas at top side i just have to write: -canvas (3cmx59px) ?

Otherwise does it possible if i have a image folder in different path to create .bat in same folder?

nconvert -ratio -resize 0 1357 -dpi 150 *.png - * is not possible to use?

PS:

It works, but the canvas is black, does it possible to make it just transparent?

Image

Re: Convert to specific cm +DPI + add canvas to top

Posted: Thu Dec 05, 2019 9:13 am
by cday
if i need a height of 23 cm (23x59px) =1357 px
Correct...

Code: Select all

nconvert -ratio -resize 0 1357 -dpi 150 tmp_bottle.png
Does that work? The help file states:

Code: Select all

-resize w h      : Scale width-height
So the 0 1357 doesn't immediately look correct, but if it works...

And for add a canvas at top side i just have to write: -canvas (3cmx59px) ?
The help file states:

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
You need to calculate the new pixel height when you add 3cm to the existing height and use that pixel value with the existing pixel width, and also use 'bottom-center' so that the new canvas is added at the top, so something like:

Code: Select all

-canvas wwww hhhh bottom-center
...where wwww and hhhh are the actual pixel values you require.

Otherwise does it possible if i have a image folder in different path to create .bat in same folder?
The following option can be used to set the output path and file name:

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
Note that % must be doubled to %% in a batch file.


The reality is that using the command line is demanding without previous experience, and very unforgiving of even small errors, so it is often necessary to be prepared to experiment to get the desired result and also to be patient. While I would like to help, there is a practical limit to the time that I can spend!!

If you have difficult progressing using NConvert I would suggest, as in my PM yesterday, that you consider using XnConvert where it should be easier to make progress. I am not sure how the processing time with XnConvert compares with that of that of a batch file using NConvert, but unless you have a very large number of files to process I don't think that it will be a consideration.

Re: Convert to specific cm +DPI + add canvas to top

Posted: Thu Dec 05, 2019 9:46 am
by cday
I see that you edited your previous post while I was replying, adding a requirement to make the output image transparent: unfortunately I don't have a good understanding of transparency... :(

If you search the forum, either directly or using a Google search, there are posts referring to making a PNG background transparent, particularly posted by XnTriq which search term you should include in the search.

And with regard to NConvert and XnConvert, note that when a desired result is obtained using XnConvert, the actions used can be exported for use in a .bat file, although at present it is necessary add the required input and output terms to the exported actions code.

Re: Convert to specific cm +DPI + add canvas to top

Posted: Tue Dec 17, 2019 5:46 pm
by xnview
i'll add '-resize' with dpi support, and '-canvas' with cm/mm support