Add album from php script

trainspottr

Joined: 2008-03-14
Posts: 1
Posted: Fri, 2008-03-14 00:57

We'd like to create an empty album every time a user makes an entry to a particular page on our site, so in our php script we'd like to add some functionality to do so.

Is it possible to do so through an interface in gallery2, or should I just go ahead and add the album and pertinent info directly into the database?

 
jcl

Joined: 2007-11-26
Posts: 2
Posted: Fri, 2008-03-14 18:07

Hi Trainspottr

We had a similar issue and wanted to import pictures as we migrate to Gallery. We needed to make top-level albums and populate them with photos from a shell script, so I wrote the attached and they did the trick for us. Perhaps they'll be a good starting point for you if they don't work how you need them. It's difficult to go straight to the database (I tried it!) and I'd strongly recommend doing the proper Gallery API calls like these scripts do.

The Gallery API can be a little tricky starting from the doc but perhaps with the starting scripts it's a little easier. The core API is documented here
http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryCoreApi.html but I also found it indepensible to read the source to work out a lot of details.

Description of attached scripts

Attached is a compressed tar file. Unpack in your Gallery2 directory: you'll get a subdirectory 'scripts' with two scripts in it. Change into scripts directory and then run the scripts. imag_g2mkalbum takes the name (and title and so on) and makes a top-level album. It prints a lot of noise, including a line saying what the gallery id is. imag_g2additem takes a top-level album name, the name you want it to be (and title and so on) and an image file.

The following is cut-and-paste (just sanitised the directory name)

ws-lon5% cd /usr/local/www/virtuals/gallery.example.com/
ws-lon5% tar xvfz /tmp/scripts.tgz
x scripts
x scripts/imag_g2mkalbum
x scripts/imag_g2additem
ws-lon5% cd scripts
ws-lon5% ./imag_g2mkalbum
Usage: ./imag_g2mkalbum albumname title summary desc keywords
ws-lon5% ./imag_g2additem
Usage: ./imag_g2additem albumname photoname title summary description filename

All are welcome to these scripts but it's your own responsibility what you do with them.

These scripts are intended to work on a generic Unix system but no testing was done outside of our production environment:

Gallery version = 2.2.4 core 1.2.0.6
PHP version = 5.1.2 apache
Webserver = Apache/1.3.34 (Unix) PHP/5.1.2
Database = mysqlt 4.1.13, lock.system=database
Operating system = FreeBSD ws-lon5.example.com 6.2-RELEASE FreeBSD 6.2-RELEASE #0: Fri Jan 12 10:40:27 UTC 2007

Hope that helps you.

All best,
J.