简体   繁体   中英

Options for using ImageMagick from PHP with MySQL blobs?

So my host provides ImageMagick on the server, but no MagickWand or IMagick API for PHP. I can do operations with the PHP exec command to manipulate images. But that requires full path file names to work, and I want to pull my images from my MySQL database. Will I have to have pull them out of the database and put them to a file everytime I want to do this? Any recommendations?

One option is to run the imagemagick process using proc_open() and write/read to/from the created process' stdin/stdout.

To have imagemagick read from stdin, you just give a dash '-' as input file. Specify /dev/stdout as the output file. Your call to image magick should look something like:

convert -scale 150x100 - /dev/stdout

Use fwrite and fread on the pipes created by proc_open to write input to imagemagick and read output back.

I haven't tried it, but I guess this should work.

If the only ImageMagick available to you can only operate on files (which is how I read your first sentence), then you will indeed have to make files from your MySQL blobs to use ImageMagick on them (and remember to clean things up afterwards). My recommendation might be to switch to a better hosting service, but I assume you have your reasons to stay with that one.

您尝试过phMagick吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM