Page 1 of 1

[SOLVED] Generate name automatically

Posted: 2013-05-08T07:58:33-07:00
by Trublux
Hi!
This is my first post, I have search in this forum and others webs but I don't find a solution for my problem.

I'm triying to create a copy (or redimension) of an image but I need to generate the name automatically.
For example I have the image: ./my-path/my-image.jpg and I want to generate an image called ./my-path/my-image_small.jpg

I try something like this (but doesn't work):

Code: Select all

convert my-path/my-image.jpg -write mpr:tree +delete mpr:tree %d/%t_small.%e
It throws this error (the phrase on spanish means "the file or directory doesn't exists"):
convert: unable to open image `0/%i.%e': No existe el fichero o el directorio @ error/blob.c/OpenBlob/2634.
Is there any way to do that? How the ImageMagick's escapes works?

ImageMagick Escapes:
http://www.imagemagick.org/script/escape.php

Thanks for answering!.

Sorry for my english.

Re: Generate name automaticaly

Posted: 2013-05-08T08:25:20-07:00
by Trublux
I have solved it:

Code: Select all

convert my-path/my-image.jpg -set filename:newname '%d/%t_small.%e' -write mpr:tree +delete mpr:tree '%[filename:newname]'

Re: [SOLVED] Generate name automaticaly

Posted: 2013-05-08T08:35:08-07:00
by GreenKoopa
I see you already found:
http://www.imagemagick.org/Usage/files/#save_escapes

Just out of curiosity, what does "-write mpr:tree +delete mpr:tree" accomplish?

Re: [SOLVED] Generate name automaticaly

Posted: 2013-05-08T08:54:54-07:00
by Trublux
I found this on this page: http://www.imagemagick.org/Usage/files/#mpr
MPR is used to save the image in memory and
It is a very common to Delete all images from the current image sequence afetr saving the images in a "mpr:" register
.
I'm not sure if that is the best way to do that but It works fine. Other methods that I tried works fine too but It throws error messages.

Re: [SOLVED] Generate name automatically

Posted: 2013-05-08T19:41:09-07:00
by anthony
Typically the mpr: is used to save an image in a named store, for later use, or retrieval via a special coder (like tile:)

In the above the save delete restore does nothing except that the first sames a copy of the image. The other to delete/restore are usless in this case.

Typically when using mpr: I am setting up an image for later use, (such as the original input image) but I don't actually need that image at that moment (or are reading via special coder) As such I often delete the image after writing to mpr:

See IM Examples, ImageFile handling, MPR
http://www.imagemagick.org/Usage/files/#mpr

Yes, the first example in this section also does a unnecessary delete, but in later examples it is nessary.
I will update the example example text to try and make it clearer