Adding URLs for cached images to gallery

CJH Member

I use Zenphoto to host and organise photos which I like to post in discussion forums (i.e. between [img] tags). My normal procedure is to drill down to the original image, right-click to 'copy image address', then paste that address between [img] tags. But then, because I want to limit the size of the image that is used in the forum, I edit that link so that it points to the cache instead of the original image, and I add a suffix (e.g. _1024) so that the resized image is created on the fly whenever it's needed. This works really well, but it's all a bit long-winded. And now I also want to share an album with another user, who will also want to post such cache URLs, and that whole procedure is likely to be too complex for that user.

So what I'd like is to show a URL to a resized (cached) image directly underneath each thumbnail, ideally with the [img] tags already around it. So my other user will simply have to select the URL underneath the thumbnail, without having to drill down and then edit the URL manually. If I can get that working, I might add two or three links under each thumbnail for different sizes.

So I have at least 2 problems in doing this myself.
1) I don't know which file to start messing with (I'm using the Basic theme)
2) I don't know how to go about editing the code.

Apart from that it's a doddle :-)

I have various coding experience, but no php and almost no html. Is anyone able to give me some pointers on how to approach this? Is there a theme that already provides this functionality?

Comments

  • acrylian Administrator, Developer
    edited April 2020

    but no php and almost no html.

    I am sorry but this will be a huge problem as you really won't get far with modifying a theme without even knowing the basics of both (and possibly CSS). Surely this one wish will lead to another and so on.

    Please read the general theming tutorial:
    https://www.zenphoto.org/news/theming-tutorial/

    It is not that hard to add such a link however Zenphoto does not direclty use these cache image urls. First there usually is the i.php image processor URL before and then Zenphoto serves the URL to the actual cached image.

    You can add this function to your theme on the appropiate theme page (image.php in this case) with the sizes you like:
    https://docs.zenphoto.org/1.5.3/function-getCustomImageURL.html

    The normal default sized image has its ow wrapper function (as the basic theme uses it):
    https://docs.zenphoto.org/1.5.3/function-getDefaultSizedImage.html

    If you print that within form and a non editable text input element a user/visitor could select that.

    Is there a theme that already provides this functionality?

    No.

  • CJH Member

    Hi - thanks for the reply. Yes, I realise that my lack of php and html experience will make this a challenge for me, but there are plenty of online resources if I find that just following the existing code doesn't teach me what I need to know.

    I'm making progress - I've duplicated the basic theme, and have managed to get almost the required text to print underneath the selected image, e.g. with
    [img]<?php echo html_encode(pathurlencode($fullimage)); ?>[/img]

    I get
    [img]/MyPhotobucket/albums/Eclipse/P1020256.JPG[/img].

    I will experiment with the various functions (thanks for the pointers), and maybe some string manipulation, to get the full resized and cached image link, including my domain name, that I'm aiming for.

  • acrylian Administrator, Developer

    Good. The URL you have is a so called webpath URL (relatively to the domain). To get the full webpath you can try something like this:

    $fullwebpathurl = str_replace(WEBPATH, FULLWEBPATH, $yourfullimageurl);

    More general info like these constants on the user guide:
    https://www.zenphoto.org/news/category/user-guide/

  • CJH Member

    Thank you. I've made a quick and dirty version that works, just by hard-coding the domain in front of the webpath. Is that FULLWEBPATH a system variable, or would I have to define that myself?

    To get the link to the resized image I simply used str_replace to change "albums" to "cache", and to insert "_1024" (etc) before the image extension.

    I can now copy these complete links straight into my forum posts. If I'm feeling adventurous I might see if I can add a 'Copy' button next to each link, but I think that might be more than I can cope with at this stage!

  • acrylian Administrator, Developer

    WEBPATH and FULLWEBPATH are defined by Zenphoto automatically (those are constants and not variables btw).

    For such a copy link you would need some JavaScript.

  • CJH Member

    Thanks for your quick reply - you beat me to it. I followed your user guide link and already discovered that they're system constants.

    Yeah, I don't have any JavaScript either. A job for another day I think :-)

  • CJH Member

    JavaScript buttons added. I should have tackled all this years ago - pasting links into forum posts now takes only a few clicks. Much more efficient, and error-free.

Sign In or Register to comment.