How to create a square thumb ?

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: helmut, XnTriq, xnview

Post Reply
Amade
Posts: 2
Joined: Mon Jun 25, 2012 1:54 pm

How to create a square thumb ?

Post by Amade »

Hi
I need to create to create a lot (>10 000) of thumbs from several pictures, with different sizes and orientations.
The result could be : 120 x 120 in the original orientation, with truncature of the rectangular parts to become a square.
Like this :
  • 1204 x 840 ---resize-ratio---> 172 x 120 ----canvas center---> 120 x 120
  • 840 x 1204 ---resize-ratio---> 120 x 172 ----canvas center---> 120 x 120
  • 600 x 800 ---resize-ratio---> 120 x 160 ----canvas center---> 120 x 120
Do you have an idea to manage the different orientations ?

Thanks

Alain
User avatar
XnTriq
Moderator & Librarian
Posts: 6512
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: How to create a square thumb ?

Post by XnTriq »

I believe this can only be done in XnView.
What's missing though is an option to crop images of varying sizes and orientations in a centered fashion.
User avatar
XnTriq
Moderator & Librarian
Posts: 6512
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: How to create a square thumb ?

Post by XnTriq »

  • Image
:idea: Solved?
Amade
Posts: 2
Joined: Mon Jun 25, 2012 1:54 pm

Re: How to create a square thumb ?

Post by Amade »

Thank you for your answer.
I understood, it's mandatory to use the GUI Xnview to start the conversion.
Actually, I need a command line to insert it in a batch process script.
I found an another method below.
Thank's
Alain
_bat file________________________________________________________________
rem %1 %2 %3 voir ci-dessous

rem fichier texte temporaire pour traitement taille
set tmpfile=%1
rem repertoire destinataire
set repcible=%2
rem nom complet du fichier image à traiter
set img=%3
rem nconvert programme
set ncv=F:\Nconvert\nconvert
rem taille du carré
set cote=120

Rem extraction largeur/hauteur
"%ncv%" -info "%img%"|find "Width ">"%tmpfile%"
for /f "tokens=2 delims=:" %%a in ('
type "%tmpfile%"') do set wd=%%a
"%ncv%" -info "%img%"|find "Height ">"%tmpfile%"
for /f "tokens=2 delims=:" %%a in ('
type "%tmpfile%"') do set ht=%%a
for %%f in ("%tmpfile%") do if exist %%f del %%f
set wd=%wd: =%
set ht=%ht: =%

Rem creation des thumb carrés dans le repertoire cible suffixés par "-sq"
if %wd% LSS %ht% (set presize=%cote% 0) ELSE (set presize=0 %cote%)
%ncv% -ratio -resize %presize% -canvas %cote% %cote% center -o "%repcible%\%%-sq.jpg" "%img%"
User avatar
XnTriq
Moderator & Librarian
Posts: 6512
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: How to create a square thumb ?

Post by XnTriq »

Thank you for posting your script, Alain :-)
I'm sure other users will find it very useful.
Post Reply