" />

mikerochford.com Being technical

26May/090

Accessing gallery2 using the API to return information about a gallery

I designed a website for a friend to sell a litter of puppies. He wanted a simple site that had galleries for each dog and one for the litter. I didn't want to maintain the site at all so I used a lot of pre built software. I chose to use Gallery2 to do all the picture stuff. It did everything I wanted (resize,rotate,etc). I didn't like how it looked though. I wanted to just have it do the back end stuff and I wanted to design the layout. To do this all I needed was the urls to access the images. Below is a function I wrote that will output all the information of a picture and its uri.

The script is located here

which outputs:

Array
(
    [0] => Array
        (
            [title] => IMG_0028.JPG
            [width] => 2272
            [height] => 1704
            [large_picture] => /p/d/71-1/IMG_0028.JPG
            [thumb_picture] => /p/d/72-2/IMG_0028.JPG
            [resized_picture] => Array
                (
                    [0] => /p/d/73-2/IMG_0028.JPG
                    [1] => /p/d/74-2/IMG_0028.JPG
                    [2] => /p/d/75-2/IMG_0028.JPG
                )

        )

    [1] => Array
        (
            [title] => IMG_0029.JPG
            [width] => 2272
            [height] => 1704
            [large_picture] => /p/d/77-1/IMG_0029.JPG
            [thumb_picture] => /p/d/78-2/IMG_0029.JPG
            [resized_picture] => Array
                (
                    [0] => /p/d/79-2/IMG_0029.JPG
                    [1] => /p/d/80-2/IMG_0029.JPG
                    [2] => /p/d/81-2/IMG_0029.JPG
                )

        )
)

You will need to modify the paths in the function to your installation.

A side note... To find gallery ids you will need to to run the following query.

mysql> SELECT g2_id,g2_title FROM g2_Item WHERE g2_canContainChildren=1;