skip to Main Content

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


  1. Chosen as BEST ANSWER

    That definitely inspired me. I added

    $layer->setImageFormat("png"); 
    

    before the base64_encode and it worked.


  2. This command will write a PNG image to base64 in Imagemagick. Sorry, I do not know how to convert to json.

    convert lena.png INLINE:lena.txt
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search