[SOLVED] Generate name automatically

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?".
Post Reply
User avatar
Trublux
Posts: 3
Joined: 2013-05-08T07:43:34-07:00
Authentication code: 6789
Location: Madrid

[SOLVED] Generate name automatically

Post 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.
Last edited by Trublux on 2013-05-08T11:44:30-07:00, edited 3 times in total.
User avatar
Trublux
Posts: 3
Joined: 2013-05-08T07:43:34-07:00
Authentication code: 6789
Location: Madrid

Re: Generate name automaticaly

Post 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]'
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: [SOLVED] Generate name automaticaly

Post 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?
User avatar
Trublux
Posts: 3
Joined: 2013-05-08T07:43:34-07:00
Authentication code: 6789
Location: Madrid

Re: [SOLVED] Generate name automaticaly

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [SOLVED] Generate name automatically

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply