toshniba
toshniba

Reputation: 382

Point ImageMagick at file format to use

I wonder if it's not possible to give ImageMagick a hint what type the input string (or file) is.

E. g. treat .sql as textfile.

I would need it to be used in php (Imagick).

The only thing I get is an exception that the file format is unknown:

no decode delegate for this image format `' @ error/blob.c/BlobToImage/361

Upvotes: 0

Views: 303

Answers (2)

toshniba
toshniba

Reputation: 382

As @MarkSetchell mentioned you can tell ImageMagick the (custom) filetype by prefixing it.

FILETYPE:FILEPATH

eg

TXT:/path/to/file.sql
  • I suppose you have to prefix a file format from specific list; identify -list format should give you that list of supported formats on linux
  • This works also with php: $im = new Imagick("txt:/path/to/file.sql");
  • Maybe someone knows how/if it works when having file contents as blob ($im->readImageBlob(...))

Upvotes: 1

Mark Setchell
Mark Setchell

Reputation: 207465

You can tell ImageMagick that a file contains text like this:

convert TEXT:stuff.sql result.png

which will give you an image of the contents of the text file stuff.sql.

So, if you want an image of a directory listing, you can do:

ls -l | convert TEXT:- listing.png

Or, if you have some SQL in a file commands.sql:

convert -background yellow -fill magenta text:commands.sql -trim result.png

enter image description here

Or, if you want it centred and with a larger border:

convert -background yellow -fill magenta text:commands.sql -trim  \
        -gravity center -extent 120%x120% result.png

enter image description here

Upvotes: 1

Related Questions