Skip to content

Pipho - PHP image gallery for iPhone

Or, what happens when Jaipho meets PHP.
Although Jaipho is meant to be used as secondary image gallery script, some of my colleagues convinced me that there should be server side solution too. They just wanted to upload photos on server and let the script do everything else.
Pipho is exactly that. It reads photos from desired folder, on the fly creates resized thumbnail and slide images, and dumps Jaipho javascript read images part. In addition, it supports text files as descriptions for both, gallery and slides.

In short, Pipho is a PHP Jaipho implementation example.

If you are making iPhone optimized site, and you already do not have gallery engine on your site, this is perfect solution for you.

Package description

It is PHP5 package written in Zend Framework coding standard, but at this moment it does not requires any class from it. PHP classes are stored in library folder. Two classes are representing the main logic.

Pipho_DeviceInfo holds information about optimal images size for device which accesses the gallery. Right now it holds only iPhone information, but in a close future, Jaipho is planned to support other smartphones too (basic Android tests are already done and it looks find). You will also use it to check will user be redirected to Jaipho at all.

Pipho_FileManager is a class which have methods for loading photos from your desired folder. It will automatically create best fit thumbnails and slide images from your original photo. Results are returned as Pipho_Image and Pipho_Gallery objects. Pipho_Image class has method getJsReadImage() which will return image data formated as Jaipho Javascript dao.ReadImage() method.

Installation

Unpack download package and upload it to your webserver. Package also contains Jaipho javascript source, what means that it can be used without any additional download.
Ensure that the photos folder (PIPHO_PHOTOS_FOLDER constant) and all it's sub folders are writable. If this is not a case, Pipho will throw an exception. You can do it by running Linux command "chmod -R 777 photos/" from your webroot.
You can test it with browser on your desktop computer.

Adding your own photos

Please note that although Pipho_FileManager class has methods for listing all galleries, in the current Pipho version, there is nowhere you can actually see the list. Only way to switch galleries is to add an url argument e.g. ?gallery_id=mygallery
Example which has implemented gallery listings can be found in integration with iUI article at http://www.jaipho.com/content/using-jaipho-iui

1. Upload your photos inside the photos folder PIPHO_PHOTOS_FOLDER. Your photos have to be organized in folders: e.g. photos/mygallery/, photos/vacation/, photos/newimages/... Gallery folder name is used as gallery_id value. Photos folder should be inside your webroot folder. In other words, the photos should be accessible with your web browser. E.g. www.mysite.com/photos/mygallery/image.jpg
2. Add description file in each folder. It should be always named _gallery.txt. First line is a title, and all other lines are considered as gallery description. Gallery description is not used at the moment. This is optional step. If you skip it, gallery name will be set as it folder name.
3. You can add titles and description for your images. Just add txt filename with the same name as image has (for myimage.jpg, add myimage.txt). First line is image title, and all other is description (same as gallery description file).

Watching galleries for the first time

In the moment when you try to see gallery with your browser, Pipho will check do the thumbnails and slides exists, and if they don't it will resize them on the fly.
It can be time consuming operation and there are two errors that PHP might throw.
- Fatal error: Maximum execution time of 30 seconds exceeded. You can increase execution time with PHP function set_time_limit ( int $seconds ).
- Fatal error: Allowed memory size of 33554432 bytes exhausted. This might happened if your photos are few MByets large. You can increase allowed memory for script with ini_set("memory_limit","64M")

Both of this functions should be added at the beginning of script where Pipho is implemented (index.php in downloaded package). It's recommended that you try all your galleries by yourself first, and after all thumbs and slides are created, you can remove those two functions.

Configuration

At the beginning of index.php is set of constants which you can change to accomplish your particular needs.

PIPHO_PHOTOS_FOLDER - holds a path to your photos folder
PIPHO_FORCE_WRITE - if set to true, the image resizing will be called on every page load, no matter if the resized images already exists. Use it only for debugging.
PIPHO_SLIDE_RESIZE_ENABLED - if you already have optimal resized images for usage on iPhone, you can turn off resizing engine by setting this const to false. Otherwise, if enabled, your images can be downgraded in quality.

PIPHO_SORT_IMAGES_ENABLED - turn on or off sort order in which the images will be shown.
PIPHO_SORT_IMAGES_SORT_TYPE - as there are different types of sorting here you can set which particular type you need. For possible values you can check at http://www.php.net/manual/en/array.constants.php
PIPHO_SORT_IMAGES_REVERSE - set it to true if for any reason you need the reverse order

PIPHO_SORT_GALLERIES_ENABLED - same as the IMAGES version, with only difference that it affects the order in galleries list.
PIPHO_SORT_GALLERIES_SORT_TYPE - same as the IMAGES version
PIPHO_SORT_GALLERIES_REVERSE - same as the IMAGES version

Please note few more things
- PHP GD library has to be installed on your server. If it is not, you'll PHP will throw error "Call to undefined function imagecreatefromjpeg()"
- Pipho requires PHP 5. Otherwise, php will throw error with text "syntax error, unexpected '{'"

Comments

PiPho with Nested Albums.

July 22, 2010 by bstigall (not verified), 1 week 23 hours ago
Comment id: 223

I have implemented album nesting into Pipho. You can view it at
http://notinclass.com/albums/mobileindex.php
This pipho installation is integrated with my php photo album on my main site.
Both share the same photo folders. This may be useful for anyone else who has both a normal site and a mobile site.
The normal album is at http://notinclass.com/photos.php.
This basically works with all the same files except i have an added "galleryfolder.php" file, and edits to the pipho classes.
The gallery.txt file now has title, then parent, then description.
I'll polish this up a little more.
Tel me what you think.

RE: PiPho with Nested Albums

July 24, 2010 by Tole, 5 days 4 hours ago
Comment id: 229

Great man, I really like it! I hope you didn't had to much trouble with it.

Consider putting back button to home page on mobileindex.php

Jqtouched

July 26, 2010 by bstigall (not verified), 3 days 12 hours ago
Comment id: 230

I redid the UI. with JQtouch because that what my webapp is going to be in now. It takes minimal changes to move from IUI to jQtouch

No Images or Thumbs

July 15, 2010 by Chris (not verified), 2 weeks 11 hours ago
Comment id: 179

Have pipho for iui installed and running, except no images show?!? They are on my server, I have checked the full url. They are being referenced correctly because the correct number of thumb holders & image holders are there and the correct Title and Text show up. Can anyone assist me please?
Many thanks in advance

RE: No Images or Thumbs

July 15, 2010 by Tole, 2 weeks 3 hours ago
Comment id: 180

Try to type in your browser the image url that Jaipho tries to use. You can check it in html source with your desktop browser.
Are there any Javascript errors?

Or, can you please post in some url where gallery can be seen?

nested albums

July 15, 2010 by bstigall (not verified), 2 weeks 1 day ago
Comment id: 178

I need this gallery to support nested folders. I'm going to see if i can write it into the code to do so. If i get it to work, I'll report back here.

RE: nested albums

July 15, 2010 by Tole, 2 weeks 3 hours ago
Comment id: 181

Nice,
I would suggest you to do next:
- to Pipho_Gallery class, add public fields $parent and $children
- in Pipho_FileManager class, change the getGalleries() method that it uses new fields on gallery class (parent/child structure).
There will be also another things to do to finish it, but this could be a start in right direction.

nested albums

July 19, 2010 by bstigall (not verified), 1 week 3 days ago
Comment id: 220

Well I have it working. With some recursion. As of now I haven't had to add new files to the folders. But I may add the parent. I have it able to support folders within folders but as of now , a folder that contains albums cannot have its own images. I'll iron out anything and report back. I still have to implement the back button.

hi there Tole, really a great

April 8, 2010 by rudolf (not verified), 16 weeks 21 hours ago
Comment id: 135

hi there Tole,
really a great job, thanks for sharing it

i managed to integrate jaipho with slideshowpro director api (cool & easy)
but i'm not quite sure who's responsible for a somewhat slow performance
...you can see it in action here: http://www.rodbuaiz.com/pipho/?gal=26
and i'd appreciate any feedback on the speed of my app-daptation
i'm guessing that maybe it's safari's handling of php

some questions/suggestions
- do you think is it possible to add a couple of preloaders? one at index.php first load, and other when images are loading... any hints where i could place them?
- if the first one is possible, i want to indicate the visitor he's about to see an iphone enabled slideshow (although this could be done in some previous page)
- i'm currently using a plugin for wordpress (wp-touch) to serve a different theme to mobile visitors, so these users are going to see the jaipho gallery... shall i restrict the user-agents allowed to see jaipho only to iphone and ipod?
(default enabled user-agents in wptouch: android, blackberry9500, blackberry9530, cupcake, dream, incognito, iphone, ipod, mini, webOS, webmate )

thanks again,
rudolf

ssp and jaipho

April 17, 2010 by Andy (not verified), 14 weeks 5 days ago
Comment id: 141

rudolf:

I am also using Wordpress and see what you are doing as far as the custom fields.....what I can't see is where you are giving the ssp path for the album to jaipho.

Any help appreciated.

Andy

RE: hi there Tole, really a great

April 8, 2010 by Tole, 16 weeks 4 hours ago
Comment id: 138

Hi Rudolf, I like your black iUI theme too. It looks really nice.

Here are the answers:
- speed - well i did not noticed anything strange or slow.
- preloader - done in Jaipho 0.53. unfortunately i didn't managed to update Pipho with that version yet. I call it splash screen and it is easy to fill it with any content you want to - just look at the html "SPLASH SCREEN" section
- wp-touch - yes, you should show Jaipho only to iPhone/iPod users for now. I have plans to extend it to support Android (and all other webkit based browsers) but it isn't that much easy as I firstly expected.

Cheers
Tole

hi Tole, nice to hear on the

April 9, 2010 by rudolf (not verified), 15 weeks 6 days ago
Comment id: 139

hi Tole,
nice to hear on the speed issue

yes, i usually prefer a black background to display photos, so there's no competing source of light in the pixels around the image

somehow i missed Jaipho 0.53 link... working on it now...
thanks again for this piece of excellent code

image anchor links

April 1, 2010 by vanarie (not verified), 17 weeks 7 hours ago
Comment id: 131

Is it possible to set up the gallery so when you click (or tap I guess) on an image, it could take you to a specific URL? I'd like to have a gallery where each image links to a different webpage.

RE: image anchor links

April 1, 2010 by Tole, 17 weeks 3 hours ago
Comment id: 132

Very good idea!
You can just add your document.location... stuff in JphSlider_Behavior.SlideTouched() method.

extra pages

March 26, 2010 by quaker (not verified), 17 weeks 6 days ago
Comment id: 126

I would like to make a about page and maybe a few others.
How would i go about doing this?

Thanks
Q

RE: extra pages

March 26, 2010 by Tole, 17 weeks 6 days ago
Comment id: 127

Well, Jaipho shouldn't be your starting point for that. You have to build your site first, with all pages you want to have. After that you can just add gallery feature with Jaipho or Pipho,
You can make your site in iUI, iWebKit or any other library you like.

Displayed thumb is not the first one

March 15, 2010 by Ivan (not verified), 19 weeks 3 days ago
Comment id: 124

In the albums list I am getting like a random thumb and not the first one, ex in the first album the thumb correspond to the 7th image in the second one it is the 4th, next one is the 9 one, etc.

RE: Displayed thumb is not the first one

March 16, 2010 by Tole, 19 weeks 2 days ago
Comment id: 125

This bug is fixed in pipho 1.01.01, so please check which version do you have.

RE: Same image twice in test gallery

February 25, 2010 by Jesse (not verified), 22 weeks 11 hours ago
Comment id: 120

I had the same problem as the person that posted the subject 'Same image twice in test gallery'.

If I had 5 images in the photos directory, all it showed was five of the same image.

I checked my PHP version and I was running 5.1.6. It was a big chore to update the PHP because my VPS had Plesk installed and apparently 5.1.6 is the latest version it supports.

I had my hosting company reprovision me a new VPS with Cpanel, which allowed me to update the PHP to 5.3.1.

After migrating my website to the new VPS with the current PHP, the duplicate images no longer existed and now this works perfectly.

Because I saw no end solution to the previous post about this problem, I thought I would pass on how I was able to resolve the issue.

Thank you for an awesome tool!!!

Portrait Images 480px Height

February 2, 2010 by Jon (not verified), 25 weeks 2 days ago
Comment id: 107

Hey Tole,
I changed the css to optimize pipho in fullscreen app mode with translucent status bar (true fullscreen images ) , problem is some of the images (not all) are not resizing to 480height. Is there a property I can change to adjust this?

Also, I've been attempting to allow users to change the slideshow speed. I tried passing some variable to the Jph object but have had no luck, any ideas?

Thanks

RE: Portrait Images 480px Height

February 3, 2010 by Tole, 25 weeks 1 day ago
Comment id: 108

Hi Jon,
First the easy one. Slideshow speed is configured with SLIDESHOW_ROLL_TIMEOUT javascript variable (Jaipho part). For details and other configurable items check the http://www.jaipho.com/content/jaipho-configuration

The image size issue is not clear that much. The max size (both, width or height) is set in Pipho_DeviceInfo php class (Pipho part). As you can see it is allready set to 480px. So there should be no problem. I tried to reproduce that behavior with my photos, but all seems to be right.

Please contact me by contact form, and than you can mail me the problematic images.

Tole

Amazing script man! Only a

January 27, 2010 by marco (not verified), 26 weeks 1 day ago
Comment id: 104

Amazing script man!
Only a question... I'd like to load in the first time the gallery and then (only after clicking gallery thumbs) the photos.
How can I do that??
tnx a lot!

Open Jaipho in thumbs mode

January 28, 2010 by Tole, 26 weeks 5 hours ago
Comment id: 105

Marco, check the "Startup modes" section on http://www.jaipho.com/content/installation-guide
I guess this is what you are looking for.

great!! tnx

January 29, 2010 by marco (not verified), 25 weeks 6 days ago
Comment id: 106

great!! tnx

Thumbnail image size

January 20, 2010 by Jon (not verified), 27 weeks 1 day ago
Comment id: 95

Great script!
I need to get thumbnails around 120 px height and 75 px width,
any thoughts on how this could be accomplished?
Thanks

RE: Thumbnail image size

January 20, 2010 by Tole, 27 weeks 1 day ago
Comment id: 97

There are 2 places where you'll have to adjust thumbs size: in css (Jaipho) where the thumbs placeholder is defined, and in php side where thumbs are created (Pipho).

1. in jaipho.css there is a selector .thumbnail. Change the width and height properties to your desired values. You'll probably want to adjust the margin property too, to adjust spacing between the thumbs.

2. in php page which displays the gallery, after the line
$device_info    = Pipho_DeviceInfo::getDeviceInfo();
add this one
$device_info->thumbsSize = 120;
Change 120 with whatever value you need.

This should fix it.

RE: Thumbnail image size

January 21, 2010 by Jon (not verified), 27 weeks 1 day ago
Comment id: 98

worked like a charm, thank you

Fullscreen Photo Description -

December 23, 2009 by robcox (not verified), 31 weeks 1 day ago
Comment id: 82

Hey there, this is an awsome app. Thank you. I added paypal buttons to the description .txt which works pretty well. The only problem is half the time I tap paypal button, the description .txt is hidden. Where can I find the code to disable the hide description text function.
robcox
http://themidnightsun.net/mobileshop/albums.php

Persistent description

December 23, 2009 by Tole, 31 weeks 1 day ago
Comment id: 84

It should be easy one. Check the JphSlider_Behavior class, and DescriptionTouched method in it.
Just remove this.mrSlider.mrCompnents.Roll(); line.

Thank you for quick response

December 23, 2009 by robcox (not verified), 31 weeks 1 day ago
Comment id: 85

I figured it out right after posting for help. You're suggestion would have been easier. I set the description to stay on and hide the toolbars when text is touched. This app is awesome and I have received so many compliments from using your gallery template.
Thanks again,
robcox

Fatal Error

November 6, 2009 by Justin (not verified), 37 weeks 6 days ago
Comment id: 68

First off thank you for this wonderful tool. I successfully created a new gallery entitled GalleryPics and added images and descriptions. However, now when I try to add more images to the gallery I get this error:

Fatal error: Call to undefined function imagecreatefromjpeg() in D:\Inetpub\AutoSites\MobileSiteTest\Final\gallery\library\Pipho\ImageResizer.php on line 32

I am getting the same error when I try try to create another gallery called GalleryPicsLarge and add different images. What am I doing wrong?

GD library is not installed

November 7, 2009 by Tole, 37 weeks 5 days ago
Comment id: 69

Check on http://www.php.net/manual/en/image.setup.php how to install it.

thanks - image gallery sequence

October 17, 2009 by JaRo (not verified), 40 weeks 5 days ago
Comment id: 64

HI,

Thanks soooo much for this. Works like a charm, except for the sequence of images.
I have my files sequentially ordered such as Slide-1.jpg, Slide-2.jpg etc. However,
it doesn't present in that order. How can I fix that?

Sort order configuration

October 17, 2009 by Tole, 40 weeks 5 days ago
Comment id: 65

Since version 1.01, there is a set of configuration options for enabling sort of both images and galleries. By default, those values are set to enable alphabetic sort, so there should be no problem with it.
Please check:
- do you have latest Pipho version installed? You can check it in CHANGELOG.txt.
- is PIPHO_SORT_IMAGES_ENABLED set to true and PIPHO_SORT_IMAGES_REVERSE to false
- try are sort options working OK with test gallery which comes with Pipho

need help with an error

September 20, 2009 by gautham (not verified), 44 weeks 4 days ago
Comment id: 51

i have uploaded your files on three different service providers web site all of them are running php5

every single site i try to open index.php i get the following error
Failed to save image [photos/test/resized/-thumb-75.jpg][2]
Failed to save image [photos/test/resized/App_Store_Badge_EN-thumb-75.png][3]

i am very new to php
please tell me what i am doing wrong or what changes i need to make for it to work

photos folder has to be writable by php

September 21, 2009 by Tole, 44 weeks 3 days ago
Comment id: 52

Your photos folder is not writable by php.
You can fix it from command prompt by running the chmod command as described in article.
If you are not familiar with command line, you can set write permissions from ftp client too. Just remember to set it recursevly.
Or you can just contact your server support and they'll set it in a minute.

Tole

Pipho typo

September 6, 2009 by GeoNomad (not verified), 46 weeks 4 days ago
Comment id: 43

FYI, there is a typo at line 92 of index.php - or at least I needed a change to make it work for me:

<?php echo $gallery->title ?>

works

<?= $gallery->title ?>

displayed title ?> on the thumbnails page.

I am not familiar with the <?= construct, so perhaps it is some php that is less than universal...

Awesome package! Many thanks for making it available. I hope to put it to good use.

After 15 minutes I am already compiling a wish list:

1. pull captions from exif
2. or - automatically create empty caption files when generating the reduced images so they can be edited. Perhaps with a default title.
3. Option to fade caption in as new slide arrives, then out after some settable delay
4. Endless loop option on slide show.
5. |<-- and -->| to start and end.
6. Automatically generate a manifest file so whole show can be saved for offline viewing.

Apologies if some of these features are there already and I missed them. I have only begun to explore...

Cheers,

Peter

JAIPHO Slideshow Offline

September 7, 2009 by GeoNomad (not verified), 46 weeks 3 days ago
Comment id: 46

As promised, I have made a page with a beta version of the code to make your PIPHO created slideshow run on an iPhone without an internet connection.

As I have put this up in a hurry, I recommend it only for those who know a bit about what they are doing - there is obviously some danger involved in being a pioneer!

benlo.com/jaipho contains the code and a bit of explanation.

You can try loading testoffline.html from your iPhone for the sample show in a form that will stay resident if you save it to the Home Screen on your iPhone or iPod Touch.

I look forward to some feedback from those who try it.

Not a typo, but will be changed

September 7, 2009 by Tole, 46 weeks 3 days ago
Comment id: 45

There is a php config value short_open_tag which enables the short echo syntax. I never encountered php installation with that feature turned off. Anyway I'll change it in future versions.

Regarding wish list, dude, it really rocks. Great ideas, and I'll certainly include it in next versions.

Thanks

Felt like a bit of coding

September 7, 2009 by GeoNomad (not verified), 46 weeks 4 days ago
Comment id: 44

Felt like a bit of coding this afternoon, so I did #2 and #6.

Now I need a nice icon for jaipho slide shows. Although right now it is not bad. When you bookmark it to the Home Screen, it uses part of the photo being displayed.

I can disconnect from the web and the slide show still works beautifully. Just like a native app. All generated automatically with one php script.

I will send you the code later so you can integrate it more prettily if you like, or I can make it available on my own site if you prefer. Just want to tidy up a bit.

Once again, thanks for making such a wonderful and inspiring tool and such nice clean code to work with.

Peter

Hi GeoNomad, Did you ever

May 29, 2010 by dango (not verified), 8 weeks 5 days ago
Comment id: 160

Hi GeoNomad,
Did you ever publish up the code to make the app save to offline (#6)..
would like to see it if poss,
thanks D.

RE: Felt like a bit of coding

September 7, 2009 by Tole, 46 weeks 3 days ago
Comment id: 47

Great man. I'm specially interested in #6. I plan to put a "Mods" page, and this could be nice one for starting it. And also, I don't have anything against publishing on other sites. I'll gladly link it.

I'm glad that you like coding standard. I'm quite proud on it, and I'll try to improve it's quality even more in future.

Tole

rate the image

August 27, 2009 by Anonymous (not verified), 48 weeks 3 hours ago
Comment id: 37

is it possible to make a rating system, so people can rate the image?

Re: rate the image

August 28, 2009 by Tole, 47 weeks 6 days ago
Comment id: 39

No I do not have plans to support rating in close future.

is it possible to do, or

August 30, 2009 by Anonymous (not verified), 47 weeks 4 days ago
Comment id: 41

is it possible to do, or maybe i can pay you to do it?

Yes it is possible

August 31, 2009 by Tole, 47 weeks 3 days ago
Comment id: 42

And, how hard it would be? It depends what are your specific requirements.
If you're satisfied with only voting, it can be done I think not to hard (vote button on top toolbar, on click opens the new page with submit form, and after submission back to Jaipho page)
But, if you want to make it fancy too, it would complicate it a bit more (popup with stars for example).
Anyhow, I prefer that you do it yourself, and I'll give you a hand in it, for free.
Please contact me on contact form with a little bit more specified requirement http://www.jaipho.com/contact

Any news in the raking system

November 15, 2009 by Pepe Gonzalez (not verified), 36 weeks 4 days ago
Comment id: 70

Hi

I was just wondering if anything has been done with the raking system. I would be interested too.

Thanks

RE: Any news in the raking system

November 16, 2009 by Tole, 36 weeks 4 days ago
Comment id: 71

No, almost nothing was done on that matter. We exchanged few mails, and than it stopped.

Same image twice in test gallery

August 12, 2009 by Anonymous (not verified), 50 weeks 2 days ago
Comment id: 27

Great work, only problem is that when i go to actually view the test gallery I see the first image twice instead of seeing both images. Just to verify, I added a new gallery of my own with 3 pictures and they all show up as the first one.

Any ideas?

Only error getting is:
[Tue Aug 11 16:41:47 2009] [error] [client 192.168.0.73] PHP Notice: Undefined index: filename in /var/www/html/iphonepic/library/Pipho/FileManager.php on line 190

RE: Same image twice in test gallery

August 12, 2009 by Tole, 50 weeks 1 day ago
Comment id: 28

Strange indeed. Check this things:
- is the GD library installed?
- are there any strange files in your photo folder (windows thmbs file, cvs files ....). you can try to remove all files except images
- look at the generated javascript source (view source in your browser), and check is there something strange in "dao.ReadImage" lines

When you fix it, please report it, so I can add it to Pipho error handling and in article too.