Reading and Saving list of Images
-
- Posts: 10
- Joined: 2010-03-22T02:57:35-07:00
- Authentication code: 8675308
Reading and Saving list of Images
Hi,
I have two problems trying to read a list of images, then save this list after doing a level correction.
My first problem:
Is it normal, that ImageMagick can't read files with long filenames or special characters in the filename?
My second problem:
I can't find a way to save the list of files after the level correction into another folder using exactly the same filenames as they had before.
Thanks for help!!
I have two problems trying to read a list of images, then save this list after doing a level correction.
My first problem:
Is it normal, that ImageMagick can't read files with long filenames or special characters in the filename?
My second problem:
I can't find a way to save the list of files after the level correction into another folder using exactly the same filenames as they had before.
Thanks for help!!
Re: Reading and Saving list of Images
How are you running the code - command line, php, shell script, batch script?
-
- Posts: 10
- Joined: 2010-03-22T02:57:35-07:00
- Authentication code: 8675308
Re: Reading and Saving list of Images
trying a command in the cmd shell
If it works the command should be executed through a *.BAT file
the problem is that this command schould open a whole folder and save all files to another folder (keeping the filenames)
*.jpg names all saved files like the first one that was opened!
If it works the command should be executed through a *.BAT file
the problem is that this command schould open a whole folder and save all files to another folder (keeping the filenames)
*.jpg names all saved files like the first one that was opened!
Re: Reading and Saving list of Images
I do most things through php but have tried out some batch files:
I am sure I have tried this but take care as it was a year or so ago. As you can see from the last line this is not a drag and drop folder onto the icon batch file.
Code: Select all
::Turn of displaying the code on the screen
@echo off
:: Read all the jpg images from the directory, resize them, add some text and save as a png in a different directory
for %%f in (%1\*.jpg) do ( convert "%%f" -resize 200x200 -pointsize 18 -fill black ^
-gravity northwest -annotate +0+0 "Some text" "%2\%%~nf.png" )
::This batch file was named resize.bat and called using "resize path\to\original\ path\to\save"
-
- Posts: 10
- Joined: 2010-03-22T02:57:35-07:00
- Authentication code: 8675308
Re: Reading and Saving list of Images
No idea how it schould work...
Can you post a reduced code for "open all *.jpg in actual folder and save it as jpg with same names in folder /new"
Or tell me where the folders have to be and how they have to be named so that your script works please.
when i take the "%1\" at the filopen and the "%2\" at the filesave out of your code Im is trying to do something but always says he can't find the files. But IM is saying it using the right filenames!?!?
This makes no sense. IM seems to read the files but then says he it can't find them??
Doesnt undestand that!
Can you post a reduced code for "open all *.jpg in actual folder and save it as jpg with same names in folder /new"
Or tell me where the folders have to be and how they have to be named so that your script works please.
when i take the "%1\" at the filopen and the "%2\" at the filesave out of your code Im is trying to do something but always says he can't find the files. But IM is saying it using the right filenames!?!?
This makes no sense. IM seems to read the files but then says he it can't find them??
Doesnt undestand that!
Re: Reading and Saving list of Images
As I say I am no batch file expert but this worked:
I have saved the file as forum_test.bat into the C folder
You can see where my original and final folders are
I always have problems with spaces in folder names - the " " around the path should sort it. I wondered if changing (%1\*.jpg) to something like ("%1\*.jpg") would help; but it didn't
Code: Select all
:: Open command prompt
:: CD to root cd\
:: Paste and run this modified to your paths forum_test.bat C:\Users\Anthony\Documents\Ballet\ C:\Users\Anthony\Documents\Ballet_png
::Turn of displaying the code on the screen
@echo off
:: Read all the jpg images from the directory and save in a different directory
:: If you are only changing the directory but keeping the name there is another way to do %%~nf.jpg but I can not remember what it is.
for %%f in (%1\*.jpg) do ( convert "%%f" "%2\%%~nf.jpg" )
You can see where my original and final folders are
I always have problems with spaces in folder names - the " " around the path should sort it. I wondered if changing (%1\*.jpg) to something like ("%1\*.jpg") would help; but it didn't
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Reading and Saving list of Images
On my Mac, the only character that really causes problems with IM is a space. And I have had no problem with long names. What special characters are you trying to use. This may be an OS issue (eg. Windows limitations or other Linux systems), but I don't know for sure. Perhaps quotes around the filenames will help. I don't recall but single quotes and double quotes behave differently (one is parsed by the OS and the other by IM, if I recall correctly what Anthony has said before).TSchlaier01 wrote:Hi,
I have two problems trying to read a list of images, then save this list after doing a level correction.
My first problem:
Is it normal, that ImageMagick can't read files with long filenames or special characters in the filename?
My second problem:
I can't find a way to save the list of files after the level correction into another folder using exactly the same filenames as they had before.
Thanks for help!!
To process a bunch of images, you cannot use convert and have multiple output images, unless you script one image at a time. However, mogrify is designed to process a whole directory using wildcards. see http://www.imagemagick.org/Usage/basics/#mogrify
-
- Posts: 10
- Joined: 2010-03-22T02:57:35-07:00
- Authentication code: 8675308
Re: Reading and Saving list of Images
It doesn't work with mogrify. Couldn't find something abaout "wildcards" in the documentation!
IM can't write images using *.jpg
I need to set a variable to save the actual filename and use it for writing the finished image.
I think the "for" loop is the best option! But how can I tell IM to save the new image under the same name like the one was opened?
Bonzo says %%f
the official IM documentation says $f
I try it that way:
for %%f in (C:\input\*.jpg) do ( convert "%%f" -linear-stretch 2x80%% "C:\output\%%~nf.jpg" )
What is wrong??
IM can't write images using *.jpg
I need to set a variable to save the actual filename and use it for writing the finished image.
I think the "for" loop is the best option! But how can I tell IM to save the new image under the same name like the one was opened?
Bonzo says %%f
the official IM documentation says $f
I try it that way:
for %%f in (C:\input\*.jpg) do ( convert "%%f" -linear-stretch 2x80%% "C:\output\%%~nf.jpg" )
What is wrong??
Re: Reading and Saving list of Images
That should run fine - if the paths are correct and if executed as batch file. (If run directly as commandline, there should be only one '%' instead of two, of course.)TSchlaier01 wrote:I try it that way:
for %%f in (C:\input\*.jpg) do ( convert "%%f" -linear-stretch 2x80%% "C:\output\%%~nf.jpg" )
What messages do you get when you execute that?
With mogrify, a similar command could look like that:
mogrify -path C:\output\ [your_operations] C:\input\*.jpg
(Note that a few options don't work with mogrify, but only with convert. It seems that "-linear-stretch" is one of them.)
Re: Reading and Saving list of Images
The %%f is the variable contaning the filename from the batch script not Imagemagick.
What does this mean ? Have you altered C:\input\ etc. to your file paths as I said or do you have a folder called input and output on your C drive ?I try it that way:
for %%f in (C:\input\*.jpg) do ( convert "%%f" -linear-stretch 2x80%% "C:\output\%%~nf.jpg" )
-
- Posts: 10
- Joined: 2010-03-22T02:57:35-07:00
- Authentication code: 8675308
Re: Reading and Saving list of Images
Ok everything works fine! The problem was an incorrect path.
Im sorry!
Thanks for your help!
Im sorry!
Thanks for your help!
-
- Posts: 1
- Joined: 2012-05-06T12:18:17-07:00
- Authentication code: 13
Re: Reading and Saving list of Images
fmw42 says one cannot process a list using convert. Must use mogrify. Not true for me using Windows 8 cmd.
Code: Select all
C:\T>convert *.jpg -quality 82 small\img.jpg
C:\T>cd small
C:\T\small>dir
...
05/06/2012 12:14 PM 642,959 img-0.jpg
05/06/2012 12:14 PM 751,246 img-1.jpg
05/06/2012 12:14 PM 556,339 img-2.jpg
05/06/2012 12:14 PM 858,051 img-3.jpg
05/06/2012 12:14 PM 913,560 img-4.jpg
05/06/2012 12:14 PM 1,088,765 img-5.jpg
05/06/2012 12:14 PM 1,107,113 img-6.jpg
7 File(s) 5,918,033 bytes
2 Dir(s) 922,427,904,000 bytes free
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Reading and Saving list of Images
My mistake for what is described above.fmw42 says one cannot process a list using convert. Must use mogrify. Not true for me using Windows 8 cmd.
But I don't believe one can specify multiple output names (one for each input image), but one can use a multi-frame format or let the output name be automatically number appended.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Reading and Saving list of Images
You can even do that....Filename Percent Escapesfmw42 wrote:fBut I don't believe one can specify multiple output names (one for each input image), but one can use a multi-frame format or let the output name be automatically number appended.
See http://www.imagemagick.org/Usage/files/#save_escapes
But you can not do this to generate multi-image files. You either put them all in one file, with name from first image (-adjoin), or only one image per file with name determined from each image's setting (+adjoin).
This is an area for review in IMv7, including montage, 'one image at a time' style, handling.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/