Problem with preloading thumbnail cache

Hi there,

I'm attempting to generate cache of all our thumbnails for all our images. The reason why I want to do this is because we have a php script that pulls a random set of thumbnails from the database and combines them into a single JPEG image that is then displayed in our email signature (the email signature calls the php script which returns the image). As far as I understand it, the script tries to get the URL of the cached thumbnails, and generates the combined image from the URLs given to it from ZenPhoto. Unfortunately, since upgrading to 1.4.3, this no longer works.

The script is below;

`


<?php</p>

if (!defined('ZENFOLDER')) { define('ZENFOLDER', 'zp-core'); }

define('OFFSET_PATH', 0);

require_once(ZENFOLDER . "/template-functions.php");

$g = isset($_GET['g'])?$_GET['g']:"retouching";

$n = isset($_GET['n'])?$_GET['n']:8;

$c = 0;

$im = imagecreatetruecolor(($n*75)-4,71);

$fill= imagecolorallocate($im,255,255,255);

imagefill($im,0,0,$fill);

$_zp_current_album = new Album($_zp_gallery,$g);

$subalbums = $_zp_current_album->getAlbums();

if(isset($_GET['r']))

{

$keys = array_rand($subalbums, $n);

} else

{

while ($c < $n)

{

$keys[$c] = $c;

$c ++;

};

};

$c = 0;

foreach ($keys as $key){

$subalbumObj = new Album($_zp_gallery,$subalbums[$key]);

$tn = imagecreatefromjpeg(".".urldecode($subalbumObj->getAlbumThumb()));

imagecopy($im, $tn,($c*75), 0, 0, 0, 71, 71);

$c++;

};

header('Content-Type: image/jpeg');

imagejpeg($im, NULL, 100);

?>

`
I'm getting errors in the error_log that suggests that the URL zenphoto returns is trying to create a new thumbnail, rather than using the cached file. So I tried to pre-cache the thumbnails. This seems to work, however when clicking on the little thumbnail icon in overview-Cache page, it gives me the Debug i.php page for the thumbnail, and the image link is broken. If I look at the link to the image, it is;

http://www.domain.com/zp-core/http://www.domain.com/cache/motion/4e8a9d558dec0163873abeba1e44603effb17979.jpg

Maybe that doesn't matter, I'm not sure if that's really the problem. The error that we get in the error_log from ZenPhoto is;

[31-Jul-2012 11:23:34] PHP Warning: imagecreatefromjpeg(./zp-core/i.php?a=retouching/nokia&i=Nokia-Guitar-RGB-Final_WEB_ZP.jpg&w=71&h=71&c=1&cw=975&ch=975&cx=0&cy=139&q=75&t=1&wmk=!) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home2/username/public_html/signature_strip.php on line 36
[31-Jul-2012 11:23:34] PHP Warning: imagecopy(): supplied argument is not a valid Image resource in /home2/username/public_html/signature_strip.php on line 37

So it seems our signature_strip.php script asks for the URL of the thumbnail, ZenPhoto doesn't think it isn't cached so it returns a URL that generates a new thumbnail, however this is something that our script cannot handle? Is that correct? Or do I not understand it properly? Apologies as I did not write the script and I am not a PHP programmer. I am trying to find the root of the problem so I can either try and fix it myself, or better describe the issue to someone who is better versed in PHP.

Any help with this would be greatly appreciated!

thanks!
Tristan.

Comments

  • acrylian Administrator, Developer
    I have no time to dig into this. Class methods like `getAlbumThumb()` get either the url to the cached image if it exists already or if it does not exist yet to the image processor to get it.

    I suggest maybe to use the full images instead (use the unprotected full image functions as full images are cached as well if set to protected for watermarks etc).
  • Hi Acrylian! Thanks for the reply. We'll look at trying to somehow crop and use the full image instead, however it still doesn't make sense to me, as all the thumbnails are cached already. I've been through the whole website (it's not that big), all thumbnails have been generated and displayed on the site, yet the getAlbumThumb() always returns the image processor. I tried using the pre-caching as a desperate last measure, as I thought that perhaps ZenPhoto was trying to fetch a different cache other than what the user sees. Is it possible there is a bug and that getAlbumThumb is not fetching the cached version when it should?
  • acrylian Administrator, Developer
    What changed is that all images are cached. Since the gallery part is file system based the cost of performance to compare always if or not is too much so they all are. But I think that was introduced with 1.4.2 already.

    You meantion a wrong link above. Try setting the webpath in the config file manually.
  • I'm sorry I'm not sure I understand? If all images are cached (including thumbnails), why does getAlbumThumb() always return the image processor? Shouldn't it always return the cache then?
  • I can confirm that all the thumbnails are cached - I've checked all the thumbnails on the site when displayed and they all are sourced from cache. So if as you say getAlbumThumb() will get the url to the cached image if it exists already then surely it should return the URL of the cached thumbnail and not the image processor?
  • acrylian Administrator, Developer
    It should not do this. If it does it might be a bug. Do you use the html static cache plugin and call the above functions on a Zenphoto theme page? In that case clear the html cache as that plainly caches a html page and if there are calls to an image processor - which it cannot know - it will cache that as well.
  • You might want to try the nightly build. If I remember correctly there was some problem with some types of thumbnails such that the cache was not being checked. Sorry, I do not remember the details.
  • Ok thanks I'll try the nightly and see how I go.
  • Hi there.

    So I tried the nightly and no luck. I have noticed however that two of our thumbnails work (out of about 80). They are from the two subalbums that have been created since upgrading to 1.4.3. So the question is, why do newly created subalbum thumbnails correctly return to getAlbumThumb() whereas all older jobs return the image processor? Obviously we would like to avoid the scenario of having to re-add all of our subalbums to get this working...?

    Acrylian you said;

    <quote>You meantion a wrong link above. Try setting the webpath in the config file manually.</quote>

    regarding the incorrect link on the debug cache page for thumbnails - to which config file do you refer?

    Also, which thumbnail cache does the getAlbumThumb() fetch exactly? When I try to pre-generate the cache, there is a list of many options - which one is ZenPhoto supposed to grab using getAlbumThumb()? I.e. which one should I be trying to generate/regenerate?

    thanks,
    Tristan.
  • acrylian Administrator, Developer
    The config file within zp-data of course.

    `getAlbumThumb()` fetches the default or standard thumb image size as set on the options. The cachemanager does allow you to set specific image sizes to precache if your theme uses custom size (e.g. those set on the theme layout and not options).
  • I suppose that if the new images work and the old ones do not the simple solution would be to purge the image cache. Then all the images would be "new" so far as the cache is concerned. You can also try using the refresh-metadata button, again makes old images look new.
  • Hi there. Unfortunately purging the image cache doesn't work. Already tried that as a troubleshooting measure when it stopped working after first upgrading to 1.4.3. Is it possible that the new jobs are caching to a different location? Or are they stored differently in the database? What might have changed to cause this?
  • Ok, so I set the webpath and server path in the config manually and it still doesn't link the thumbnail in the debug correctly.

    Following this process;

    1. Edit album
    2. Click 'Cache album images'
    3. Apply 'default_85_cw71_ch71_thumb'
    4. Provided they are not already cached, thumbnails are created and (in my test case) three small thumbnails appear on a line '3d/job { x | x | x } [3 images]'
    5. Click on one of the tiny thumbnails before [3 images] and it opens a new debug page for the thumbnail image;
    6. Following the 'Debug i.php | Arguments:' list, there is a line that says 'Image:'. After 'Image:' there is a broken link to the newly generated thumbnail.

    The broken link listed on the debug page is;
    /zp-core/http://www.domain.com.au/cache/3d/job/eb0cbe39a7151d199226c5485578323f60ec486b.jpg

    When it should be;
    http://www.domain.com.au/cache/3d/job/eb0cbe39a7151d199226c5485578323f60ec486b.jpg

    Is this related possibly to my thumbnail woes? Or something else?

    Thank you kindly for all your help and responses so far.
  • Haven't tried refreshing the metadata. Will do now and will report back.
  • Ok. So I;

    1. Cleared the image cache.
    2. Recreated the default and admin thumbnails.
    3. Refreshed the metadata.
    4. Browsed the whole website to check existence of thumbnails and force it to generate any that might not have been generated for some strange reason

    and now still no thumbnails returned by getAlbumThumb() in our script.

    And, unfortunately, I now no longer get the thumbnails from the two newer albums that I used to get successfully.

    In our theme options, we have the thumbnail size set to 85. Crop is set to 8.23529411765%, left and right, top and bottom. It says next to thumb size 'Standard thumbnails will be scaled to 85 pixels.' When I navigate the the album or subalbum on the webpage and check the dimensions of the thumbnails, they are indeed 85px x 85px. Under the sizes provided by the cache manager, 'default' is set to size 85, crop 71 x 71. How do I pre-generate the thumbnails used by our theme? Or is this not possible?
  • I also tried feeding in the error I get back from the script into a browser to try and see what the image processor is returning;

    In a browser window I entered this (an extract from the error I got in the logs);

    http://www.mydomain.com.au/zp-core/i.php?a=3d/top-model&i=TM_spaceship_Final_WEB_ZP.jpg&w=71&h=71&c=1&cw=911&ch=911&cx=293&cy=94&q=75&t=1&wmk=!

    And I get a blank page. The logs then have;

    Backtrace: USER NOTICE: Too few arguments! Image not found. in /home2/username/public_html/zp-core/functions-image.php on line 33

    trigger_error called

    from imageError (functions-image.php [33])

    from i.php [41]
  • acrylian Administrator, Developer
    If it is the site linked in your profile all thumbs seem to be cached to me. Some of the big images are not when I visited them the first time but then they are.

    The site is crashed a few times in Safari 6 but that might be a server glitch.
    I recommend to check the JS stuff you are doing as FF reports a few errors.
  • Hi acrylian. Yes it is the site linked in my profile. As I far as I can tell too, the thumbs are cached. This is why I cannot work out why our script does not work, and is always getting the image processor. You can test it if you go to our domain and add;

    /signature_strip.php

    you can see any relevant php details at;

    /phpinfo.php

    Thanks for the heads up on the javascript errors - it's nothing major - I believe it's related to using an older version of google analytics. I've used Safari 6 a fair bit on the site and am yet to see problems myself so I'm hoping that is just a server glitch.
  • acrylian Administrator, Developer
    If I access that page I see this html:
    ``

    That is of course really nonsense. COuld you maybe tell us what this is supposed to do? If that is supposed to be a custom page in Zenphoto context it is wrong:
    http://www.zenphoto.org/news/theming-tutorial#custom-pages-with-the-example-of-archivephp-and-sl
  • The little x's (`3d/job { x | x | x } [3 images]) are because the particular image failed to render for the size. Clicking on the x is supposed to take you to the debug page where anyting displayed about the failure will be shown. What actaully gets shown will depend on you PHP settings. If you have it set to show PHP errors on the WEB page, then these errors will be displayed and help you know why the images did not render.

    The broken link itself seems to be a bug. Fixed in the nightly build. But probably not useful in this case since the image will not be rendered.
  • Hi acrylian. Thanks for the response. Actually it's not nonsense, it's what the script is meant to do - only it unfortunately doesn't work anymore since upgrading to 1.4.3 because of the behavior of getAlbumThumb() that I've been describing. I explained in my first post what it does, but perhaps I wasn't clear? If so I apologise. The script grabs a number of random thumbnails from subablums, then attempts to combine those thumbs together and returns them as an image. Because this is for use in an email signature, the data that is returned is an image so it can be displayed in the email client. It is now failing, where it used to work fine, because since 1.4.3 (seemingly regardless of the existence of a cached thumb or not) zenphoto is returning the image processor instead of the cached thumb, and the php function used in our script to combine the images is expecting a jpg back and not a php url. As I said, I tried using the url that the image processor is returning, and I couldn't seem to get it to make an image anyway, but I'm not sure if it's supposed to on it's own or not?

    sbillard - I'm sorry I wasn't more clear - there aren't three x's on the line (`3d/job { x | x | x } [3 images]) - there are three thumbnail images, correctly generated and rendered. When I click on one of them it takes me to the debug page, and to the bug I described. Thanks for fixing it, perhaps it may help me.

    I understand this is frustrating for you, and I apologise. It is very frustrating for me as well, and I am trying to work out what has changed so I can fix it, or if it is in fact a problem in zenphoto, and I am trying to give the best feedback I can to you so that it can be resolved. It seems that our script is perhaps still ok, and something may have gone awry somewhere in zenphoto's thumb caching, as I had two thumbs working ok with the script (from subalbums that had been created since upgrading to 1.4.3), but nothing else worked, and since I cleared the cache and regenerated all the thumbnails, and refreshed the metadata, now even those two don't work.

    Please let me know if anything is still unclear, or if you need any more information from me.

    thanks,
    Tristan.
  • The bug fix will not help you. It comes into play only when attempting to debug and image renditions.

    I guess the first thing I would do if I were you is reset the `Obscure cache filenames` option so you have a better clue as to what is in your cache. With that not set the file names have the sizing parameters imbedded. Most likely you are not getting a thumbnail of the same sizing as you have cached.

    There could be many reasons for this, but most likely would be that when you run that script you do not have the theme (and therefore the theme options) properly established.
  • Hi there. Thanks for the quick response. I'll keep trying.

    Could you please remove our website URL from the earlier post?

    Thanks again,
    Tristan.
  • acrylian Administrator, Developer
    I indeed missed the explaination above somehow, sorry for that. I would try to make a theme custom page out of this, then you can be sure that all Zenphoto functions are available.

    The url has been removed.
Sign In or Register to comment.