Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: PHP Photo Album script v2.0 help

  1. #1
    Join Date
    Aug 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile PHP Photo Album script v2.0 help

    I was wondering how in the PHP Photo Album script v2.0 script if I can modify it to use the file names of the pictures as the photo description. I want to parse out the extension in the file names and simply use the names for all the photo descriptions. I looked at the php file and I know the file names are passed and I think the file is gets these paths and file names, but I can't seem to figure out how to parse them and assign them to the auto-generated description.

    The DD files are located at http://www.dynamicdrive.com/dynamici...photoalbum.htm

    Thanks for your help

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Sure. This is untested, but should work. Inside ddphpalbum.js, find the lines below, and add to it the line in red:

    Code:
    		var desc=(desc && desc!="")? '<br />' + desc.replace(/(%i)|(%d)|(%s)/g, function(m){
    				return (m=="%i")? i+1 : (m=="%d")? albumvar.images[i][2] : ""
    			}) : ''
    		desc=(desc=="%filename")? albumvar.images[i][1].split('.')[0] : desc
    Then, for a particular album, if you want the description to just be the filename of each image, inside its invocation code, do the following:

    Code:
    new phpimagealbum({
    	albumvar: myvacation, //ID of photo album to display (based on getpics.php?id=xxx)
    	dimensions: [3,2],
    	sortby: ["file", "asc"], //["file" or "date", "asc" or "desc"]
    	autodesc: "%filename", //Auto add a description beneath each picture? (use keyword %i for image position, %d for image date)
    	showsourceorder: true, //Show source order of each picture? (helpful during set up stage)
    	onphotoclick:function(thumbref, thumbindex, thumbfilename){
    		thumbnailviewer.loadimage(thumbref.src, "fit2screen")
    	}
    })
    Last edited by ddadmin; 08-07-2009 at 01:29 AM.
    DD Admin

  3. #3
    Join Date
    Aug 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have added the first if statment that is commented out at the beg of this function (this is only a partial copy of the function). the rest is the original code. I think it is getting the desc array values from the html file that is calling this function. I wanted to override the values and insert the name of the image. I put an alert on this.albumvar.images[i][1] so I know this is where the file name is housed. I want to take this and use it as the desc but get an error that says phpimagealbum is undefined. Please any suggestions would be appreciated.

    function phpimagealbum(setting)
    {
    this.albumvar=setting.albumvar
    for (var i=0; i<this.albumvar.images.length; i++){


    //if (this.albumvar.images[i][1])
    //{
    //this.albumvar.desc[i]= this.albumvar.images[i][1]
    //}else
    //this.albumvar.desc[i]="no name found"
    // }
    if (this.albumvar.desc[i]) //if a manual desc exists for this image
    this.albumvar.images[i][3]=this.albumvar.desc[i] //extend image array with desc
    }

  4. #4
    Join Date
    Aug 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ddamin,
    Thank you I will try it.

  5. #5
    Join Date
    Aug 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ddadmin,
    I get "%filename" for each picture. If I only have one album do I leave autodesc: an empty string in the html file?

  6. #6
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    No, autodesc should be set to "%filename". Anyhow, I just realized an error in my code above. The line in red should read the following instead:

    Code:
    		var desc=(desc && desc!="")? '<br />' + desc.replace(/(%i)|(%d)|(%s)/g, function(m){
    				return (m=="%i")? i+1 : (m=="%d")? albumvar.images[i][2] : ""
    			}) : ''
    		desc=(desc.indexOf('%filename')!=-1)? albumvar.images[i][1].split('.')[0] : desc
    DD Admin

  7. The Following User Says Thank You to ddadmin For This Useful Post:

    james438 (08-08-2009)

  8. #7
    Join Date
    Aug 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks that worked I concatenated the break.

  9. #8
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I have a related question. After making the updates listed in this thread I notice that some of the filenames are a little longer than the images and end up pushing the images to the right. Is there a way to do a character wrap for the file names?
    To choose the lesser of two evils is still to choose evil. My personal site

  10. #9
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    If you mean trim the filenames if they exceed a certain length, you can try:

    Code:
    desc=(desc.indexOf('%filename')!=-1)? albumvar.images[i][1].split('.')[0].substring(0, 10) : desc
    where 10 means the first 10 characters.
    DD Admin

  11. #10
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I was thinking more along the lines of a character wrap, but I like your suggestion more because it helps to avoid vertical pushdown of the second or third row.
    To choose the lesser of two evils is still to choose evil. My personal site

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •