ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

convert images in a channel:entries loop to base64

January 23, 2012 2:12pm

Subscribe [2]
  • #1 / Jan 23, 2012 2:12pm

    aircrash

    293 posts

    I need to convert a list of images from within a channel entries loop to base64.

    I think I can do it with php basically like this:

    <?php
     $encodedImages = array(
      'assets/test-image-1.jpg',
      'assets/test-image-2.jpg',
      'assets/test-image-4.jpg',
      'assets/test-image-5.jpg',
     );
    
     if (isset($_GET['id']) && in_array($_GET['id'], $encodedImages)) {
      echo 'data:image/jpg;base64,' . base64_encode(file_get_contents(realpath( './' . $_GET['id'])));
     }
    ?>

    but I need to get the image path from my channel entry data into a php array.

    I can output a list of image paths in an EE template using the code below, but I’m not sure how to combine the two bits of code to encode the images (or if it is even possible). Has anyone done something like this?

    {exp:channel:entries channel="pages"}
    '{image}',
    {/exp:channel:entries}

     

     

  • #2 / Jan 24, 2012 8:06pm

    e-man

    1816 posts

    Not sure if this is helpful but CE Image has a bulk tag to process images inside an entry:
    http://www.causingeffect.com/software/expressionengine/ce-image/user-guide/basics (look for “bulk tag”).
    Maybe you can adapt the plugin for your needs?
    This is also available as a php class http://www.causingeffect.com/software/php/ce-image/user-guide and Aaron is a most helpful dev if you contact him.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases