Hello,
Fatman's official script to display a photo externally is nice, but it *resizes* images to fit in the height/width instead of *fitting* them. So if I have portrait orientation pics, and I ask for a photo that is within 400 px wide x 300 px tall, it squashes the image and makes people look fat.
It seems as if this should have a very simple fix, namely, replace this:
`getCustomImage(null, $width, $height, null, null, null, null)`
with this:
`getCustomSizedImageMaxSpace($width, $height)`
Nope. Doesn't work. No code is output, the php dies unexpectedly.
Can someone suggest what I'm doing wrong? Is there a known bug with getCustomSizedImageMaxSpace()?
Comments
1. Declare the following outside of the main image display loop:
`global $_zp_image_current;`
2. Replace "$randomImage->getCustomImage(...)" with:
`getCustomSizedImageMaxSpace($width, $height)`
(NO $randomImage reference).
Why this works:
Fatman's script created the object randomImage, and then used the getCustomImage function that resides inside all image objects (defined in the zenphoto "image" class).
HOWEVER, getCustomSizedImageMaxSize() is NOT a function of the image class! Instead, it is a template function that depends on an image set in the global variable $_zp_current_image. This variable is usually set in theme loops by some code in each page template. But fatman's script never actually put any information in $zp_current_image, so the function had nothing to pull information from. Hence the early script death I kept seeing.
Below is my current revision to Fatman's script:
`
<?php
/*******************************************************************************
* random.php: return random image (updated from fatman's script by G. Lebec)
*******************************************************************************
* URL Parameters:
* num - number of images
* width - width of random image.
* height - height of random image.
* class - css class for random image.
* album - album to get the random image, default is root.
*
*******************************************************************************
*/
define('OFFSET_PATH', true);
require_once("template-functions.php");
global $_zp_current_image;
isset($_REQUEST['num']) ? $num = $_REQUEST['num'] : $num = 0;
isset($_REQUEST['width']) ? $width = $_REQUEST['width'] : $width = 50;
isset($_REQUEST['height']) ? $height = $_REQUEST['height'] : $height = 50;
isset($_REQUEST['class']) ? $class = $_REQUEST['class'] : $class = '';
isset($_REQUEST['album']) ? $album = $_REQUEST['album'] : $album = '';
header ('Content-Type: text/html; charset=' . getOption('charset'));
while ($num > 0) {
if ($album == '') {
$_zp_current_image = getRandomImages();
} else {
$_zp_current_image = getRandomImagesAlbum($album);
}
echo 'getTitle() . '" class="' . $class . '">' .
'getTitle() . '" />';
$num--;
}
?>
`
Note that this removes the HTML size formatting, too, which is a good thing. The only caution I have is that I don't know ZenPhoto inside and out - hijacking $_zp_current_photo in this way may actually break something in a way I am ignorant of. I don't believe that is the case, but caveat user.
Cheers!
-GLL
Thanks for that, I only installed ZenPhoto yesterday so I'm catching up as fast as I can! Love the app in general by the way. Here is an updated script, does this pass muster?
`
<?php
/*******************************************************************************
* random.php: return random image (updated from fatman's script by G. Lebec)
*******************************************************************************
* URL Parameters:
* num - number of images
* width - width of random image.
* height - height of random image.
* class - css class for random image.
* album - album to get the random image, default is root.
*
*******************************************************************************
*/
define('OFFSET_PATH', true);
require_once("template-functions.php");
isset($_REQUEST['num']) ? $num = $_REQUEST['num'] : $num = 0;
isset($_REQUEST['width']) ? $width = $_REQUEST['width'] : $width = 50;
isset($_REQUEST['height']) ? $height = $_REQUEST['height'] : $height = 50;
isset($_REQUEST['class']) ? $class = $_REQUEST['class'] : $class = '';
isset($_REQUEST['album']) ? $album = $_REQUEST['album'] : $album = '';
header ('Content-Type: text/html; charset=' . getOption('charset'));
while ($num > 0) {
if ($album == '') {
$randomimage = getRandomImages();
} else {
$randomimage = getRandomImagesAlbum($album);
}
makeImageCurrent($randomimage);
echo 'getTitle() . '" class="' . $class . '">' .
'getTitle() . '" />';
$num--;
}
?>
`