0

Is it possible to create a temp file server side for viewing an image?

I've some images & they're displayed from server but I want to have them watermarked... Found out about the Imagick Class, used composite... It can be viewed when sent as header but I need it somehow visible for the tag.

I don't want to uses 'write image' & create a new image from the composited image. I'm trying to use it as client Side thing (I'm not familiar with JS... Yes, I'll look into it but need an alternative till then).

Another alternative that I'm aware of is I should control that WHILE uploading the images but I've already uploaded quite a few so... Any help appreciated!

1 Answer 1

0

Have you tried using the function that generates your image as a src attribute for the <img /> tag?

I don't know exactly how your code is, but I am thinking the end result could be something like:

<img src="data:image/jpeg;base64,<?php echo base64_encode($image_headers); ?>">

You basically output the headers inside the image src as a base64 encoded string.

What you should keep in mind is that you should adjust the image/jpeg type to the corresponding type of your image.

For example:

  • For JPG, JPEG files it would be image/jpeg
  • For PNG files it would be image/png
  • For WEBP files it would be image/webp

And of course the encoded string should be an image of the corresponding format.

7
  • Thanks for the super quick reply. I'll give it a try in a few & let you know if that works. Also, I'll share the code as well.
    – Manny
    Commented Apr 24, 2020 at 18:28
  • So I updated the tag with the new code but it still outputs a bunch of gibberish text instead of the image
    – Manny
    Commented Apr 24, 2020 at 18:52
  • Could you update your question with the image generating code? The full function preferably. I'm a little blind here :) Commented Apr 25, 2020 at 3:22
  • I actually figured it out, I didn't understand what exactly you meant at first but I roamed around & got it. It works perfect now except for one thing. If I right click & open it in a new tab, it says the entire encoded base64 structure... If there's an alternative to rename it or so, as the source images... Here's the source code stackoverflow.com/q/61419943/13168285
    – Manny
    Commented Apr 26, 2020 at 12:26
  • As far as I am aware you are not able to do this since the entire image is inside the src. It's not a generated file, it's literally the raw code of the image. If you need to be able to save it with a file name, you'd have to save the image file on your server and output that instead. Except for that, did my answer work for you? Commented Apr 26, 2020 at 18:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.