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.
Comments
Note that 1.4 is nowhere near the current release version so you should respectively might need to upgrade.
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.
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
Thank you again
Nelson.
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:'<?php echo $HR ?>'
});
}
$(document).ready(function() {
requestHR();
});
//then I construct the URL to the cached image:
<?php
$cache_path=implode ('cache', explode ('albums', $_zp_current_image->webpath));
$hrPath=implode('_' . $HR_size . '.', explode('.', $cache_path));
?>
//I use that path in the link
">high res
The code for downloading the photo is pretty simple:
<?php
$dir = SERVERPATH . $_GET['path_to_image'];
header('Pragma: public');
header('Cache-Control: public, no-cache');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($dir));
header('Content-Disposition: attachment; filename="' . basename($dir) . '"');
header('Content-Transfer-Encoding: binary');
readfile($dir);
?>
`
Hope this helps somebody else, or anybody with a better solution should correct my mistakes
Nelson.
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 <pagename> 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).