Open JPEG/PNG image in photoshop when downloaded f

2019-09-02 19:13发布

问题:

I have a PHP web application running where admin can download the image files submitted by users. Now, I want it in a way that when admin downloads those images into his PC, he should just double click on that image and it should open in Photoshop if installed. Is this possible? Or is there a way to write a psd file out of jpg/png file? I'm looking forward for your answers.

Thanks

回答1:

You can load a JPEG file using the PHP ImageMagick extension and send it as PSD to the browser with its MIME type.

I believe the PSD support is always available in ImageMagick, but check it out; I might be wrong.

Then, the browser must know to reroute that file to PhotoShop. It is likely that the PhotoShop installation already instructs it that way, but you may also need to configure the browser instead.

$image = new Imagick();

$image->readImage("myImage.jpg");

$image->setImageFormat('psd');
header('Content-type: image/photoshop');
die($image);

A really dirty way of doing things is to "define" your own MIME type:

$jpeg = 'test.jpg';

Header('Content-Type: application/jpeg-with-photoshop');
Header('Content-Length: ' . filesize($jpeg);
readfile($jpeg);

The browser will, the first time, pop up a windows saying "WTF? What do I do with a jpeg-with-photoshop file?!?". Just click "Open With > Choose Application > Find application on disk > clickety clickety click > Photoshop" and the browser will remember, and always open what is really a JPEG file by launching Photoshop. Photoshop will then recognize the object as a JPEG file and open it properly.



标签: php image shell