Ahmar Ali
Ahmar Ali

Reputation: 1068

PHP Alter Base64 Encoding of image

I am developing an application and for that I need to generate multiple copies of same image with unique base 64 encoding.

However I am not sure that if I add a random string like "aasasa" in between my image code whether it will corrupt image or it will display properly?

Is there any way to achieve this?

    $imageDataEncoded = base64_encode(file_get_contents($_FILES["fileToUpload"]["tmp_name"]));

     $imageData = base64_decode($imageDataEncoded);
     $imageData="asasasas".$imageData;
     $source = imagecreatefromstring($imageData);

Thanks Ahmar

Upvotes: 0

Views: 87

Answers (1)

user7000326
user7000326

Reputation:

It's not entirely obvious why you would want to do this (maybe there is a better way to achieve what you're after). Anyways, I would try and change the image metadata. By changing the metadata you are "not changing" the image itself.

Further reading material:

http://php.net/manual/en/book.exif.php

http://php.net/manual/en/function.iptcembed.php

http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html

This can be achieved by using a EXIF library, but be aware that these changes are obviously way more performance intensive and can slow down your load time significantly, especially if you do this on a lot of pages.

Upvotes: 1

Related Questions