How to work with CSV as source?

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

Moderators: XnTriq, helmut, xnview

Post Reply
chilly_bang
Posts: 2
Joined: Wed May 16, 2018 3:06 pm

How to work with CSV as source?

Post by chilly_bang »

Hi

I have a CSV file with image urls (remote, as http://, and local, as file:///) and according image dimensions. Is it possible with NConvert to process images from CSV as source? Like:
  • open an image from the first CSV line,
  • resize it to dimensions, which belongs to this image in CSV,
  • compress and save image (with the same file name into given folder)
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: How to work with CSV as source?

Post by cday »

chilly_bang wrote: Wed May 16, 2018 3:17 pm I have a CSV file with image urls (remote, as http://, and local, as file:///) and according image dimensions. Is it possible with NConvert to process images from CSV as source? Like:
  • open an image from the first CSV line,
  • resize it to dimensions, which belongs to this image in CSV,
  • compress and save image (with the same file name into given folder)
I think the only possibility would be to use external code to read the CSV file for each image in turn and set variables to the image dimensions and, if necessary, the image path and file names...

I can confirm that, in Windows, NConvert can accept cmd.exe variables as parameters for image dimensions, for example; I haven't tested for input file names but imagine that would likely work too.
chilly_bang
Posts: 2
Joined: Wed May 16, 2018 3:06 pm

Re: How to work with CSV as source?

Post by chilly_bang »

@cday - i'm not very comfortable with NConvert scripting. Would you say, the code at this url: http://www.netikka.net/tsneti/info/tscmd137.htm would be useful for the task i described? I'm interesting specially for usage of temp file as the source of image dimensions
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: How to work with CSV as source?

Post by cday »

chilly_bang wrote: Wed May 16, 2018 4:44 pm @cday - i'm not very comfortable with NConvert scripting. Would you say, the code at this url: http://www.netikka.net/tsneti/info/tscmd137.htm would be useful for the task i described? I'm interesting specially for usage of temp file as the source of image dimensions
Let me say first that although I've been a Window user since 3.11, I never really expected to use the command line: I've become moderately familiar with NConvert, but my scripting experience is limited to using a very small subset of cmd.exe ('DOS') in batch files.

At a quick look, the code you posted illustrates among other things the use of variables defined by the SET lines, but doesn't directly relate to the core issue of reading a CSV file and getting parameters in it into variables. The filelist parameter in NConvert is provided to enable input files to be read from a text file list, rather than listed sequentially as the last item at the right end of the command line, so is not directly relevant.

I've only had a quick look, but don't see it solving the core problem. Depending on your own level of experience, you might if necessary concentrate first on getting selected values in a CSV file into 'DOS' variables. You might try some Googling in the hope of finding a solution quickly, otherwise posting just that core part of the problem on one of the general programming forums would seem to be the way forward.

Note: It might be as well to check first that NConvert will indeed accept a 'DOS' variable as an input file name in a command line, I can't easily check immediately as I'm out of the house and on Linux.

Edit:

I've checked and NConvert will accept input file names as 'DOS' variables.

You therefore need to find a way of placing the CSV parameters you need into 'DOS' variables, which can then be used in an NConvert command line in a batch file. Once you can do that for a single image you will presumably need to elaborate that for multiple files, which may require a loop.

Out of interest, what is the structure of the CSV files you need to read?
User avatar
Firekeeper
Posts: 1
Joined: Mon Jul 05, 2021 4:42 pm

Re: How to work with CSV as source?

Post by Firekeeper »

Actually, in this case external code to read the CSV file for each image might might work out, however it would be something like 70% - 30 % and only 30% that it would actually work! In this particular case, NConvert has to be the best possible solution actually, well at least that is my own opinion. I also had a similar situation with a csv file, and that file was also filled with a lot of image urls. I have used Nconvert from the beginning, and it worked perfectly, so I would recommend you to try it out.
Post Reply