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.

Image file width

December 29, 2011 10:56am

Subscribe [2]
  • #1 / Dec 29, 2011 10:56am

    chiste

    18 posts

    Hi, I need to output the width of my images so I can use a Jquery image carrousel. Every image has a different width.

    I’m using the {width} variable but nothing is rendered. This is my code:

    {exp:channel:entries channel="clients" status="open" orderby="title" sort="asc" }
    {logo}
     <li>
      {path}{filename}.{extension}
     </li>
    {/logo}
    {/exp:channel:entries}

    But this is what I get:

    <li>
     <a href="http://croslandmaquinarias.com.pe/images/uploads/logos_clientes/energy.png">http://croslandmaquinarias.com.pe/images/uploads/logos_clientes/energy.png</a>
    </li>

    I dont want the width of a manipulation, I need the image full size width.

    What could be missing?

  • #2 / Dec 29, 2011 12:14pm

    ahmad saad

    364 posts

    {width} not available variables in File Fields see http://ellislab.com/expressionengine/user-guide/modules/channel/custom_fields.html

    {width} is variables in File Module http://ellislab.com/expressionengine/user-guide/modules/file/file_tag.html

    the only way to do what u wont is useing query module to do that with (file table)

  • #3 / Dec 29, 2011 12:47pm

    chiste

    18 posts

    Ok it almost worked, but height and width are stored in a single field separated by a space. So when I do this:

    {exp:query sql="SELECT file_hw_original FROM exp_files WHERE title = '{filename}.{extension}'"} {file_hw_original} {/exp:query}px

    I get something like: style=“width: 300 200px;”

    Any ideas on how to get only the width?

     

  • #4 / Dec 29, 2011 1:11pm

    ahmad saad

    364 posts

    u can use php explode function to return array then u get the key 1 of array.

    however u will use php tag I prefer using getimagesize function like this:

    {exp:channel:entries channel="clients" status="open" orderby="title" sort="asc" }
    {logo}
    <?php $file_path="{path}{filename}.{extension}"; $imginfo = @getimagesize($file_path); $width=$imginfo[0]; $height=$imginfo[1];?>
     <li>
      {path}{filename}.{extension}
     </li>
    {/logo}
    {/exp:channel:entries}
  • #5 / Dec 30, 2011 3:29am

    John Henry Donovan

    12339 posts

    Hi chiste,

    Did that help you?

    There are also add-ons available that achieve the same thing here and here

  • #6 / Dec 30, 2011 8:21am

    chiste

    18 posts

    Ahmad solution is perfect for me because it allows me to store the image height in a variable and divide it by two, which I need to center the image vertically in the middle.

    Thanks

  • #7 / Dec 30, 2011 4:19pm

    Dan Decker

    7338 posts

    chiste,

    Glad to see that Ahmad was able to provide you exactly what you were looking for, thanks Ahmad!

    If you need assistance in the future, just let us know in a new thread.

    Cheers!

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

ExpressionEngine News!

#eecms, #events, #releases