I have a routine that uses PHP/ImageMagick to loop through a .psd and save the layers as PNG files. I now want to be able to output them as base64 in a JSON object instead without the intermediate step of saving them to a file. Can anyone point me in the right direction?
I have tried base64_encode() on the layer eg:
foreach ($psd as $no => $layer) {
// Skip the first layer
if (!$no) {
continue;
}
echo base64_encode($layer);
but the output doesn’t seem to be in the correct format.
2
Answers
That definitely inspired me. I added
before the base64_encode and it worked.
This command will write a PNG image to base64 in Imagemagick. Sorry, I do not know how to convert to json.