0

given an image file path, I want to get its content - than add metadata to that content (either EXIF, IPTC, XMP etc.) and then display that image's content, with that metadata included (probably in base64 format), in an HTML tag without saving the file.

why without saving the file on server? the action I'm trying to perform is for a case a user saves the image file to his computer, for copyright purposes - I want his IP and the my site's URL to be stored in the metadata of the image he downloaded. there will be thousands of users viewing the image in a minute so I cannot create temporary copies of this image on server.

I can generate either a JPEG or PNG format image - any format needed in order to make it work.

I currently know how to store IPTC meta data in a JPEG image using PHP's "iptcembed" but of course that stores (saves) the file.

rami300
  • 69
  • 9

2 Answers2

0

I know you said you cannot create temporary files, but there is a manual temporary file that you delete yourself, and a PHP managed temporary file.

Have a look at tmplfile(), which allows you to save the file on the server but it will be cleared once the request is done.

Then you can do all the things you need, then get the content of the tmpfile as base64 and return that content. The file will be gone afterwards, so more or less it happened in memory per request.

David
  • 83
  • 6
  • thanks, but thing is - file creation at the rate of views I expect - will create a big load on the web server, I'm really trying to avoid this – rami300 Dec 28 '20 at 11:24
  • 1
    Does iptcembed maybe return the file instead of change it? Maybe you don't even need to store te file at all? And if iptcembed returns the content you can also look at php://memory to open a file in memory rather than on disk. – David Dec 29 '20 at 13:45
0

I somehow missed the fact that the third argument of iptcembed, "spool", can do the job:

Spool flag. If the spool flag is less than 2 then the JPEG will be returned as a string. Otherwise the JPEG will be printed to STDOUT.

I tried it with the various options and it worked for me.

rami300
  • 69
  • 9