Portrait pictures only

phgrove

Joined: 2002-10-10
Posts: 101
Posted: Sun, 2003-05-18 14:06

i am trying to alter the random-block code such that it will only display portrait pictures. I have added the following line sof code in on the random-blocvk code but i get some errors.

if (isset($index)) { 
    $id = $album->getPhotoId($index); 
	list($iWidth, $iHeight) = $album->getThumbDimensions($id);
	echo "width = $iWidth\n";
	echo "hieght = $iHeight\n";
	echo "" 
        ."<a href=" .makeAlbumUrl($album->fields["name"], $id) .">" 
        .$album->getThumbnailTag($index) 
        ."</a>"; 
     	    
    $caption = $album->getCaption($index);

A demo of the code can be seen at http://www.petergrove.co.uk/index2.php
Could someone explain to me what i am doing wrong. oncve i get the dimesions i will be able to either choise another picture or display that one. After that i would like to be able to resize the picture as well.

Peter

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Mon, 2003-05-19 06:37

Well, you should probably add a new flag, say, $isPortrait or something, and set it to FALSE. Then put the code in a while() loop:

$isPortrait = FALSE;
while (!$isPortrait) {
   $album = chooseAlbum();

   if ($album) {
      $index = choosePhoto($album);
   }

   if (isset($index)) {
      [...] code to test dimensions, resize image, print [...]
   }
   [...]
}

-Beckett (

)

 
phgrove

Joined: 2002-10-10
Posts: 101
Posted: Mon, 2003-05-19 08:10

Thanks beckett! The main problem i have is i am not sure how i get the dimension of the image usign the code already inthe gallery program. Once i get the dimension the rest i can do quite easily. Any chance you might be able to give me some pointers on this.

Peter

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Mon, 2003-05-19 08:16

Well... you're right so far in using the *thumbnail* dimensions rather than the image dimensions, because you could have a portrait image but have the thumbnail cropped to be a landscape.

What you have above, using getThumbDimensions() is definitely the way to go. What problems are you having with it? It seems to list them just fine.

-Beckett (

)

 
phgrove

Joined: 2002-10-10
Posts: 101
Posted: Mon, 2003-05-19 11:12

If you keep refreshing the page [url]www.peterrgove.co.uk/index2.php [/url] you will find you eventually some error like this :-

Quote:
ERROR: requested index [42_06] out of bounds [30]
Fatal error: Call to a member function on a non-object in /home/www/petergro/gallery/classes/Album.php on line 317

Any idea's?
Thanks
Peter

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Mon, 2003-05-19 21:24

Sounds like the error which can be fixed by changing this line:
$choose = rand(1, $count);
to
$choose = rand(1, (int) $count);

-Beckett (

)

 
phgrove

Joined: 2002-10-10
Posts: 101
Posted: Tue, 2003-05-20 21:24

Fixed it by using the code

	list($iWidth, $iHeight) = $album->getThumbDimensions($index);

instead of

	list($iWidth, $iHeight) = $album->getThumbDimensions($id);

Silly mistake.

Now all i need to finds out is how you resize an image on the fly to fit a cretain cell in a table, or is this better done on the clients machine.

Peter