Member
Member
nelson   2013-04-18, 18:08
#1

Hi,
I have a requirement from a client, he needs two buttons in the page for two different sizes of the current image, those two buttons would allow the user to download such images, different from the original image size
I'm using a custom template, in there, I used getCustomImageURL() for both links; the returned value from getCustomImageURL is sent to a custom php script which sends the image to the browser.
It works great, and the user can download the two different sizes; BUT ONLY if those two sizes had been viewed before, that is, if they are in the cache already. If the image was viewed at the custom size, I get the URL to the cache file, but if not, I get the URL to the image processor
How can I make getCustomImageURL return the URL only after the image processor has finished with it (in cache) ?

Using ZPhoto 1.4

Thanks for any pointer to a solution

Nelson.

Administrator
Administrator
acrylian   2013-04-18, 18:31
#2

Make sure the images are already cached when accessed. Use the cache_manager plugin to do that.

Note that 1.4 is nowhere near the current release version so you should respectively might need to upgrade.

Member
Member
sbillard   2013-04-18, 18:33
#3

You could have your script run a background request for the images via an "ajax" request when the page loads if the image is not already in the cache.

You can find an example of this in the development build html_metatags.php script. Do a search on the variable $htmlmetatags_need_cache for the details.

Administrator
Administrator
acrylian   2013-04-18, 18:35
#4

True, that is the more sophisticated way...;-)

Member
Member
nelson   2013-04-18, 18:37
#5

Thank you acrylian for the prompt response, yes, I'm a little behind in the updates, currently on v1.4.1.6
Don't know if I asked the wrong question, but the problem I'm facing is none of the images are in the cache, since they are custom sized
how can I get a custom size image on the fly? is your answer the solution? using the plugin to force-generate those custom sized images?
Thanks

Member
Member
nelson   2013-04-18, 18:42
#6

sbillard, thank you very much for the idea; you are right, AJAX was the step I was missing in my current process
Thank you again

Nelson.

Member
Member
nelson   2013-04-19, 03:10
#7

For future reference ...
At the end I made an AJAX call to generate the images in cache, but had to build the URL to the cached images (used in the anchor tag), because I found no way to run the getCustomImageURL function after the AJAX call completed (Don't know yet how to call a template function from JavaScript).

I did it like this:

`
//get the URL to the resized image
$HR_size=2000;
$HR=getCustomImageURL($HR_size);

//then I made the AJAX call

function requestHR(){
$.ajax({
cache:false,
type:"POST",
url:''
});
}
$(document).ready(function() {
requestHR();
});

//then I construct the URL to the cached image:

//I use that path in the link
high res

The code for downloading the photo is pretty simple:

Administrator
Administrator
acrylian   2013-04-19, 07:57
#8

Since JS and PHP are different you cannot call a PHP function directly via JS.
You probably could use another ajax call to get the new cached url.

Generally you can for example call "custom theme pages" (those have the url /page/ where the file name minus .php extension. That could contain a function that then returns the new url via ajax as well.

Regarding the download, we also have a downloadlist plugin that may be of help for the download (it does bascially what you do but it also has download statistics available).

Member
Member
sbillard   2013-04-19, 17:15
#9

In the example I referenced you will see PHP code testing for the uri being to the image processor and saving it into an array. Then at the end of the script, if it did find some images needing caching it generates some javascript code to do the caching. Among the code is a definition of a js array containing the links needing to be fetched and a loop doing an ajax request for each of the elements in that array.

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.