Reading and Saving list of Images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".

Reading and Saving list of Images

Postby TSchlaier01 » 2010-07-30T04:55:41+00:00

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!!
TSchlaier01
 
Posts: 6
Joined: 2010-03-22T02:57:35+00:00

Re: Reading and Saving list of Images

Postby Bonzo » 2010-07-30T05:43:48+00:00

How are you running the code - command line, php, shell script, batch script?
ImageMagick examples mostly using php http://www.rubblewebs.co.uk/imagemagick/
New section ( still in progress ) showing examples of all the operators http://www.rubblewebs.co.uk/imagemagick/operator.php
Bonzo
 
Posts: 1174
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: Reading and Saving list of Images

Postby TSchlaier01 » 2010-07-30T06:35:50+00:00

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!
TSchlaier01
 
Posts: 6
Joined: 2010-03-22T02:57:35+00:00

Re: Reading and Saving list of Images

Postby Bonzo » 2010-07-30T07:26:56+00:00

I do most things through php but have tried out some batch files:
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"


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.
ImageMagick examples mostly using php http://www.rubblewebs.co.uk/imagemagick/
New section ( still in progress ) showing examples of all the operators http://www.rubblewebs.co.uk/imagemagick/operator.php
Bonzo
 
Posts: 1174
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: Reading and Saving list of Images

Postby TSchlaier01 » 2010-07-30T08:28:23+00:00

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!
TSchlaier01
 
Posts: 6
Joined: 2010-03-22T02:57:35+00:00

Re: Reading and Saving list of Images

Postby Bonzo » 2010-07-30T08:50:45+00:00

As I say I am no batch file expert but this worked:

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" )


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
ImageMagick examples mostly using php http://www.rubblewebs.co.uk/imagemagick/
New section ( still in progress ) showing examples of all the operators http://www.rubblewebs.co.uk/imagemagick/operator.php
Bonzo
 
Posts: 1174
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: Reading and Saving list of Images

Postby fmw42 » 2010-07-30T09:33:30+00:00

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


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

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
User avatar
fmw42
 
Posts: 4813
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Reading and Saving list of Images

Postby TSchlaier01 » 2010-08-06T01:19:52+00:00

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??
TSchlaier01
 
Posts: 6
Joined: 2010-03-22T02:57:35+00:00

Re: Reading and Saving list of Images

Postby Drarakel » 2010-08-06T05:56:49+00:00

TSchlaier01 wrote:I try it that way:

for %%f in (C:\input\*.jpg) do ( convert "%%f" -linear-stretch 2x80%% "C:\output\%%~nf.jpg" )

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.)
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.)
Drarakel
 
Posts: 365
Joined: 2010-04-07T12:36:59+00:00

Re: Reading and Saving list of Images

Postby Bonzo » 2010-08-06T07:35:59+00:00

The %%f is the variable contaning the filename from the batch script not Imagemagick.

I try it that way:

for %%f in (C:\input\*.jpg) do ( convert "%%f" -linear-stretch 2x80%% "C:\output\%%~nf.jpg" )

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 ?
ImageMagick examples mostly using php http://www.rubblewebs.co.uk/imagemagick/
New section ( still in progress ) showing examples of all the operators http://www.rubblewebs.co.uk/imagemagick/operator.php
Bonzo
 
Posts: 1174
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: Reading and Saving list of Images

Postby TSchlaier01 » 2010-08-06T07:56:20+00:00

Ok everything works fine! The problem was an incorrect path.
Im sorry!
Thanks for your help!
TSchlaier01
 
Posts: 6
Joined: 2010-03-22T02:57:35+00:00


Return to Users

Who is online

Users browsing this forum: el_supremo, Google [Bot] and 3 guests