Display Image Dimensions and File Size

I don't seem to find a setting to display the image dimensions and file size along with the image. [In fact, it would be even better if I could get it displayed ON the image as an overlay]. What am I missing?

Comments

  • OK. I DO NOT program in Php. But I did take a look at the code for the Zenpage theme and ZP. After a few Google searches looking for Php syntax, on line 106 of the file image.php, I made the following code change:

    <?php printImageDesc(); 
    $imgSz = getSizeFullImage(); 
    echo ' Width: ' . $imgSz[0] . ' Height: ' . $imgSz[1]; ?>
    
    

    That gets me the full image width and height when I'm viewing the full image. It relies on printImageDesc() using the current image being viewed when nothing (null) has been passed to it.

    I'm sure I can now figure out how to get the file size. But this only solves my problem for the Zenpage template. It seems ludicrous that 15 year old software exists and absolutely nobody has ever wanted to display the image dimensions and sizes. There must be a better way!!!

    Someone, please... enlighten me!

  • acrylian Administrator, Developer

    OK. I DO NOT program in Php

    If you like to modify more default behaviour of existing themes there will be no way around this as you probably already realized (plus knowledge in HTML, CSS and JS may not hurt) ;)

    Ready made themes are always suggestion to use and to adapt if you want/need anything different. They cannot fit for everyone.

    We have theming tutorial that covers the basics of theming:
    https://www.zenphoto.org/news/theming-tutorial/

    Zenphoto theming is quite flexible but "exploiting" that requires naturally some knowledge.

    It relies on printImageDesc() using the current image being viewed when nothing (null) has been passed to it.

    No, it relies on the image context that is set on image.php and not printImageDesc() which also relies on that context. Most template function do rely on the right context.

    The optional parameter of getSizeFullImages() is to request a specific image object which is documented: https://docs.zenphoto.org/function-getSizeFullImage.html

    It seems ludicrous that 15 year old software exists and absolutely nobody has ever wanted to display the image dimensions and sizes.

    You already figured out the right way to display the size of the original image.

    For the size that is really nothing Zenphoto specific as plain PHP functions exist for that:

    $filesize = filesize(getFullImageURL());

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

  • acrylian: Sorry. I should have said "OK. I DO NOT program in Php, but I have 46 years of professional experience in programming, including 28 different programming languages ... plus a few languages I've never used professionally. My favorite language is Perl"

    Thanks for your reply. Guess I'll have to live with making manual modifications, eh? :)

    BTW: For me, getFullImageURL() returns "images[5]" and not the file size.

  • acrylian Administrator, Developer

    Guess I'll have to live with making manual modifications, eh? :)

    Well, yes, the best is always to make your own custom theme to really cover your personal needs. You have a lot freedom to do what you need which is one of the real strenghts of Zenphoto.

    BTW: For me, getFullImageURL() returns "images[5]" and not the file size.

    Do you perhaps have the full image set to protected on the options? Then try getUnprotectedImageURL() instead.

  • acrylian: thanks for your reply and suggestion!

    Under: Admin->Options->Images

    The option for "Full image protection" was set to: 'download.' I changed it to 'Unprotected' as per your suggestion.

    I changed line 106 of image.php in the Zenpage theme to read (NOTE: I've reformatted the code below for ease of reading - it's actually one long line in the real image.php file!):

    
    $filesize prints nothing visible on the screen.
    
            <?php $imgDim = getSizeFullImage(); 
            $filesize = filesize(getFullImageURL()); 
            echo 'Dimensions: ' . 
            $imgDim[0] . 'px ' . 
            $imgDim[1] . 'px . 
            File Size: ' . $filesize . 
            '<br />'; 
            printImageDesc(); ?>
    
  • acrylian Administrator, Developer
    edited March 2019

    You are right, my bad. I always forget that "getFullImageURL()" returns a webpath url for theme usage and that filesize() actually needs a serverpath url.

    This works:

    $fullpath = SERVERPATH . '/'. ALBUMFOLDER .'/' . $_zp_current_album->name . '/' . $_zp_current_image->filename;
    $filesize = filesize($fullpath); 
    echo $filesize;
    

    It will put out bytes so a quite huge number. You can use byteConvert($filesize) to convert that to a better readably kb or mb value.

    I guess I will indeed consider to add a helper function getFullImageFilesize() to make things easier.

    Addition: This is much shorter (there are most always several ways).
    $fullpath = $_zp_current_image->getFullImage(SERVERPATH);

    Btw, the next version wil have said function and the support build already does.

Sign In or Register to comment.