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?".
However when the filename is very large, it looks bad. I want to limit the width to 200x and truncate filename, when it's more than that, something like:
Somelongf...jpg
ImageMagick by itself cannot truncate the file names in the middle if too long. You will have to compute the length of the text and truncate it yourself with some other scripting code. You test if your text is too long by adding -debug annotate and parsing the output for the width of the text. You may have to iterate to get the right size. You can then edit your text and try again, or just use a smaller font. I do not see where you have specified the desired width for label:. If you do that and leave off the pointsize, IM will pick the best pointsize to fit the width. See http://www.imagemagick.org/Usage/text/#label
I can't see an easy way of doing this. You could do it like this, supposing the filename is "A_very_long_name.jpg":
1. Make an image for "A_very_long_name.jpg". If it is within your width limit, job done.
2. Make three images, for "A_very_long_name" and "..." and ".jpg". Suppose the widths are W1, W2 and W3. They need to fit into a total width T.
3. Calculate x = T-W2-W3. This is the new width for the first part of the name. Crop it (chopping off the right side) to this width. Then append the "..." and ".jpg" images.
This will often chop the first part of the name within a character. With more effort, you could crop at a character boundary.
You could do this in a shell script. It might be possible as a pure ImageMagick command. (In fact, I'm sure that is possible, but it might not be pretty.)
thanks guys. I see how I can do this but that's pretty complex
What about making the label with imagemagic so that the filename is not written in one line but in two instead?
Let's say
Very
long
name
.jpg
?