On album.php I am looking to display the first image of the album as a preview to the album if possible. Basically to be able to display the current albums first image adjacent to the thumbnails. In fact any image would do from that album but ideally the first.
Sorry, I am not a coder but would really appreciate the help
Comments
`"><?php printAlbumThumbImage(getAlbumTitle()); ?>`
That should work. Stick it wherever you want that thumbnail.
edit: unexpected results. sorry, i'm new to zenphoto
$sql = "SELECT filename FROM ". prefix("images") ." WHERE albumid = ".urlencode($_zp_current_album->id)." ORDER BY id DESC LIMIT 1";
$result = mysql_query($sql);
$image = get_album_image($result['filename']);
echo 'name).'&i='. $image.'.jpg" alt="Test" />';
?>
`
I'd expect it to be something along these lines though this returns the album name and not the filename. I will sort out the dimensions later.
`<?php<br />
$images = $_zp_current_album->getImages(0);
$first_image = new Image($_zp_current_album, $images[0]);
$first_url = $image->getSizedImage(zp_conf('image_size'));
$first_desc = $image->getDesc();
?>
" alt="<?php echo $first_desc; ?>">
`
See how simple? This should work (barring any code mistakes, I haven't tested it or anything). This way you can change the size or whatever you like. If you want a custom sized image, use this line instead (replacing the $size, $width etc. with numbers or `null`s):
`$first_url = $first_image->getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy);`
It helps to know the classes inside-out of course ;-) I should write some good documentation, but the code is clean enough to read.
I digress..... I am still having trouble with this though. I get the following error when trying to use the code, This is refering to,
`
$first_url = $image->getSizedImage(zp_conf('image_size'));
`
I can't see what I am missing. I am using the 1.0.3 release.
`$first_image = new Image($_zp_current_album, $images[0]);
$first_url = $image->getSizedImage(zp_conf('image_size'));
$first_desc = $image->getDesc();`
with
`$first_image = new Image($_zp_current_album, array_shift($images));
$first_url = $first_image->getSizedImage(zp_conf('image_size'));
$first_desc = $first_image->getDesc();`
Two problems: first, the array, `$images` doesn't use numbers for keys, it uses image names. Thus, you can't just get the first one by `$images[0]` (I forgot ;-) The function `array_shift` gives you the first item off any array, regardless of how it's organized, so it works better. Second problem was that I used `$image` instead of `$first_image` for the variable names in the second two lines.
I tested it this time, so it should be good. :-)
So something you should learn from this are variables and variable names (the ones you use have to match the ones you define), and array indices. Those are pretty general programming ideas, not specific to PHP, so very useful concepts.
`
`
Without mod rewrite,
`
`
This occurs regardless of what album I am in.
(For clarity, I am runnning this on the album.php page) Thanks.
note above a few comments, tris mentions the use of getcustomimage. that's probably what you want to use instead of getsizedimage, as getsizedimage will return the default image size from the zp-config file. getcustomimage will in turn show you a custom image size of your choosing (note the size, width, height params in that function).
Does that help?
That's why the 595 shows for the size parameter because if you are pulling from the unchanged (default) zp-config, the size is set to 595.
I understand that the default parameter for the image size and this is returned from "zp_conf('image_size')". I have tried both techniques (custom image size and default) but with no success. I was simply trying to get the basic function to return the image name and description and then I would worry about the dimensions of the image returned. Small steps etc.
As per the html I posted above, the problem is not with the default image size returned (that bit of the function works) but the fact it doesn't return the image name or any value for the description (alt text).
e.g
<img src="/~website path~/zen/zen/i.php?a=test&i=image.jpg&s=595" alt="description">
`<?php<br />
$images = $_zp_current_album->getImages(0);
$first_image = new Image($_zp_current_album, array_shift($images));
$first_url = $first_image->getCustomImage(null, 400);
$first_desc = $first_image->getDesc();
?>
" alt="<?php echo $first_desc; ?>">`
That should be correct.
The URL's in your images above are also correct, I don't see anything wrong with them. Zenphoto's images are all passed through a script, they're never directly accessed -- thus, you'll get "/zen/i.php?a=album&i=image&w=400" from the code above, and that's how it's supposed to be. With mod_rewrite on, it's even cleaner, "/~album name~/image/595" is perfect, and should work. Is that image not showing?
Let's clarify: What do you want to do exactly?
Also, can we see your site? Thanks!
Has it occurred to you that the image might not have a description? Try adding one.
Also, you can get the title using this:
`<?php echo $first_image->getTitle(); ?>`
Try making the image tag like this:
`" alt="<?php echo $first_image->getTitle(); ?>">`
To sum up, the image is not being displayed and neither is the description as the alt text ( I understand that not all my images have descriptions but some do and they should be displayed).
@ Tris, can we forget about mod rewrite for the moment? From your reply above, no. 5230, you said,
"…..thus, you'll get '/zen/i.php?a=album&i=image&w=400' from the code above, and that's how it's supposed to be."
Well I am not getting that (as per my earlier reply), it is not returning the html for the image part. e.g the "&i="part doesn't have the image name after it. Unless I am mistaken, how is the browser supposed to render the page and display the image if it isn't stated in the image tags?
`“/zen/zen/i.php?a=album&i=&s=400â€`
Hopefully you understand my problem now.
Replace:
`$first_image = new Image($_zp_current_album, array_shift($images));`
With:
`$first_image = array_shift($images);`
And when you upgrade to 1.0.4, out this week most likely, you'll have to go back to the first one ;-) Sorry for the confusion.
`Warning: Missing argument 3 for getcustomimage() in /x/x/x/x/zen/class-image.php on line 201
Warning: Missing argument 4 for getcustomimage() in /x/x/x/x/zen/class-image.php on line 201
Warning: Missing argument 5 for getcustomimage() in /x/x/x/x/zen/class-image.php on line 201
Warning: Missing argument 6 for getcustomimage() in /x/x/x/x/zen/class-image.php on line 201
Warning: Missing argument 7 for getcustomimage() in /x/x/x/x/zen/class-image.php on line 201`
`$height, $cropw, $croph, $cropx, $cropy`
Anyone know how I can resolve this?
For now I have just removed the above from class-image.php, but I would rather there was another way, so the full functionality is intact, and also to make upgrading easier.