[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do i use phpthumb() with this picLens php script?

Posted on 2008-11-10
57
Medium Priority
?
752 Views
Last Modified: 2012-05-05
Hello,

PicLens generally works on the principle that you have 2 folders of images - 1 with the original images and another with the thumbnails. I would like to generate the thumbnails on the fly using phpthumb() (http://phpthumb.sourceforge.net/) instead.

My photos are stored in www.globexposure.net/includes/travel_pics/72/

Please can someone show me how the attached script can be modified to do this?


Many thanks for your help
if ($handle = opendir("mysite/images/originals/")) {
 
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<item><media:thumbnail url=\"mysite/images/thumbs/$file\"/><media:content url=\"mysite/images/originals/$file\"/><link>mysite/images/originals/$file</link>";
}
$path = "mysite/images/originals/$file";
$size = getimagesize("$path", $info);
if(isset($info['APP13'])) {
$iptc = iptcparse($info['APP13']);
 
$datum_j = str_split($iptc['2#055'][0], 4);
$datum_m_d = str_split($datum_j[1], 2);
 
print "<title>$datum_m_d[1]-$datum_m_d[0]-$datum_j[0] - {$iptc['2#120'][0]}</title></item>\n";
 
} elseif ($file != "." && $file != "..") {
print "<title></title></item>\n";
}
}
 
closedir($handle);
 
} else {
print "<p>Error: You're error message. If you use quotes in you're message, put a \ (backslash) before it, others you will get a wide screen.</p>";
}

Open in new window

0
Comment
Question by:Daniish
  • 31
  • 26
57 Comments
 
LVL 6

Expert Comment

by:James Looney
ID: 22920791
Good morning,

Looks like you need to adjust the image path in the script to match the image path you say your images are in www.globexposure.net/includes/travel_pics/72/)

So, based on that, I would recommend trying this version of your script. Copy/paste it into a new text file called something like thumb_test.php and drop it into your web root (probably the /www folder). Then test it out by using this url: http://www.globexposure.net/thumb_test.php



<?php
$originals_path = '/includes/travel_pics/72/';
$thumb_path = '/includes/travel_pics/thumbs/';
 
if ($handle = opendir($originals_path)) 
{
	while (false !== ($file = readdir($handle))) 
	{
		if ($file != "." && $file != "..") 
		{
			echo "<item><media:thumbnail url=\"".$thumb_path."$file\"/><media:content url=\"".$originals_path."$file\"/>
			<link>".$originals_path."$file</link>";
		}
		$path = $originals_path."$file";
		$size = getimagesize("$path", $info);
		if(isset($info['APP13'])) 
		{
			$iptc = iptcparse($info['APP13']);
			 
			$datum_j = str_split($iptc['2#055'][0], 4);
			$datum_m_d = str_split($datum_j[1], 2);
			 
			print "<title>$datum_m_d[1]-$datum_m_d[0]-$datum_j[0] - {$iptc['2#120'][0]}</title></item>\n";
		}
		elseif ($file != "." && $file != "..")
		{
			print "<title></title></item>\n";
		}
	}
	 
	closedir($handle);
}
else
{
	print "<p>Error: You're error message. If you use quotes in you're message, put a \ (backslash) before it, others you will get a wide screen.</p>";
}
?>

Open in new window

0
 

Author Comment

by:Daniish
ID: 22920982
Thanks for that but at present i'm just getting the error message.

I don't see any reference to phpThumb() in the script though!
I have downloaded phpthumb and installed it to:
www.globexposure.net/includes/phpthumb/

I had a look at Image Magick but can't quite figure how this is installed.

I got this script from:
http://developer.cooliris.com/dev_forum/comments.php?DiscussionID=66&page=1#Item_0
... and was under the impression it would generate a media RSS file - but i don't see any new file being generated.

Any tips greatly appreciated
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22921032
So here is a question - are your original images so large that you truly need to generate separate thumbnails?

Also, if you want to pursue phpThumb - can you please paste in there the error message you are getting?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Daniish
ID: 22921241
My images are generally around 300-600K, correct me if i'm wrong but, thumbnails would i expect make quite a bit of difference to the load time.

The error message i get is the one from your script above:

Error: You're error message. If you use quotes in you're message, put a \ (backslash) before it, others you will get a wide screen.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22921358
Ya images that big might make a difference in the feed load - depending on how many items you want to include in your feed.

Ok, so that sounds like either it can't find your image folder, or the permissions on that folder need to be opened up. So for testing purposes, can you make sure that your originals folder is world readable?

It might be smarter to have a script that will create the thumbnails for your in one run, instead of trying to use phpThumb to do them dynamically. So let's try this.

First, make sure that GD is enabled in the version of PHP you are using. Create a simple php file with this in it:
<?php
phpinfo();
?>
Run that so it dumps out your PHP environment to the browser. Search in the browser screen for the "gd" section (you can search for "GD Support"). Make sure it says "enabled". If so, proceed .....

So with GD enabled, we can try the following.

Try a new php file called something like generate_thumbs.php and put this code in it. Run this in your browser (or on command line) and when it is done, with any luck, you will have thumbnails in the "thumbs" folder (note that I am having it put your originals from the  "72" folder into a subfolder of "thumbs" called "72" so that if you add more originals later on to a new folder, we won't overwrite the thumbs in 72 - but you can adjust as you wish):


<?php 
$imagefolder='/includes/travel_pics/72/';
$thumbsfolder='/includes/travel_pics/thumbs/72/';
$pics=directory($imagefolder,"jpg,JPG,JPEG,jpeg,png,PNG");
$pics=ditchtn($pics,"tn_");
if ($pics[0]!="")
{
	foreach ($pics as $p)
	{
		createthumb($p,"tn_".$p,150,150);
	}
}
 
/*
	Function ditchtn($arr,$thumbname)
	filters out thumbnails
*/
function ditchtn($arr,$thumbname)
{
	foreach ($arr as $item)
	{
		if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;}
	}
	return $tmparr;
}
 
/*
	Function createthumb($name,$filename,$new_w,$new_h)
	creates a resized image
	variables:
	$name		Original filename
	$filename	Filename of the resized image
	$new_w		width of resized image
	$new_h		height of resized image
*/	
function createthumb($name,$filename,$new_w,$new_h)
{
	$system=explode(".",$name);
	if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
	if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
	$old_x=imageSX($src_img);
	$old_y=imageSY($src_img);
	if ($old_x > $old_y) 
	{
		$thumb_w=$new_w;
		$thumb_h=$old_y*($new_h/$old_x);
	}
	if ($old_x < $old_y) 
	{
		$thumb_w=$old_x*($new_w/$old_y);
		$thumb_h=$new_h;
	}
	if ($old_x == $old_y) 
	{
		$thumb_w=$new_w;
		$thumb_h=$new_h;
	}
	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
	if (preg_match("/png/",$system[1]))
	{
		imagepng($dst_img,$filename); 
	} else {
		imagejpeg($dst_img,$filename); 
	}
	imagedestroy($dst_img); 
	imagedestroy($src_img); 
}
 
/*
        Function directory($directory,$filters)
        reads the content of $directory, takes the files that apply to $filter 
		and returns an array of the filenames.
        You can specify which files to read, for example
        $files = directory(".","jpg,gif");
                gets all jpg and gif files in this directory.
        $files = directory(".","all");
                gets all files.
*/
function directory($dir,$filters)
{
	$handle=opendir($dir);
	$files=array();
	if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}}
	if ($filters != "all")
	{
		$filters=explode(",",$filters);
		while (($file = readdir($handle))!==false)
		{
			for ($f=0;$f<sizeof($filters);$f++):
				$system=explode(".",$file);
				if ($system[1] == $filters[$f]){$files[] = $file;}
			endfor;
		}
	}
	closedir($handle);
	return $files;
}
?>

Open in new window

0
 

Author Comment

by:Daniish
ID: 22921552
OK i have checked the permissions on the image folders and they are all set to chmod: 755

GD Support is enabled: http://www.globexposure.net/phpinfo.php

I have saved your script to:
http://www.globexposure.net/generate_thumbs.php

but it doesn't generate any thumbnails :(
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22921734
Sorry, it should have generated them and put them in the folder /includes/travel_pics/thumbs/72/

If that folder does not exist, you can either create it manually or use this code in place of my original post (this one creates the thumb dir if it does not exist - it also checks to make sure the path to the originals is good.):



<?php 
$imagefolder='/includes/travel_pics/72/';
$thumbsfolder='/includes/travel_pics/thumbs/72/';
 
if(!is_dir($imagefolder))
{
    die('Image folder path appears invalid.');
}
if(!is_dir($thumbsfolder))
{
	mkdir($thumbsfolder);
}
 
$pics=directory($imagefolder,"jpg,JPG,JPEG,jpeg,png,PNG");
$pics=ditchtn($pics,"tn_");
if ($pics[0]!="")
{
        foreach ($pics as $p)
        {
                createthumb($p,"tn_".$p,150,150);
        }
}
 
/*
        Function ditchtn($arr,$thumbname)
        filters out thumbnails
*/
function ditchtn($arr,$thumbname)
{
        foreach ($arr as $item)
        {
                if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;}
        }
        return $tmparr;
}
 
/*
        Function createthumb($name,$filename,$new_w,$new_h)
        creates a resized image
        variables:
        $name           Original filename
        $filename       Filename of the resized image
        $new_w          width of resized image
        $new_h          height of resized image
*/      
function createthumb($name,$filename,$new_w,$new_h)
{
        $system=explode(".",$name);
        if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
        if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
        $old_x=imageSX($src_img);
        $old_y=imageSY($src_img);
        if ($old_x > $old_y) 
        {
                $thumb_w=$new_w;
                $thumb_h=$old_y*($new_h/$old_x);
        }
        if ($old_x < $old_y) 
        {
                $thumb_w=$old_x*($new_w/$old_y);
                $thumb_h=$new_h;
        }
        if ($old_x == $old_y) 
        {
                $thumb_w=$new_w;
                $thumb_h=$new_h;
        }
        $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
        imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
        if (preg_match("/png/",$system[1]))
        {
                imagepng($dst_img,$filename); 
        } else {
                imagejpeg($dst_img,$filename); 
        }
        imagedestroy($dst_img); 
        imagedestroy($src_img); 
}
 
/*
        Function directory($directory,$filters)
        reads the content of $directory, takes the files that apply to $filter 
                and returns an array of the filenames.
        You can specify which files to read, for example
        $files = directory(".","jpg,gif");
                gets all jpg and gif files in this directory.
        $files = directory(".","all");
                gets all files.
*/
function directory($dir,$filters)
{
        $handle=opendir($dir);
        $files=array();
        if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}}
        if ($filters != "all")
        {
                $filters=explode(",",$filters);
                while (($file = readdir($handle))!==false)
                {
                        for ($f=0;$f<sizeof($filters);$f++):
                                $system=explode(".",$file);
                                if ($system[1] == $filters[$f]){$files[] = $file;}
                        endfor;
                }
        }
        closedir($handle);
        return $files;
}
?>

Open in new window

0
 

Author Comment

by:Daniish
ID: 22921843
I get the following error:
Image folder path appears invalid.

I have also tried setting an absolute path with:
http://www.globexposure.net/includes/travel_pics/72/

but this didn't work either - do you suppose it might be because the image filenames have spaces in them - or something else entirely?
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22921964
woops. I'm a dummy.

You'll need the entire path to the image folders, or, depending on the type of server you are on this might work:

change these two lines
$imagefolder='/includes/travel_pics/72/';
$thumbsfolder='/includes/travel_pics/thumbs/72/';

to this

$imagefolder='includes/travel_pics/72/';
$thumbsfolder='includes/travel_pics/thumbs/72/';

this is assuming that your php script is in the root directory and the directory structure looks like this:

/www/
        /includes/travel_pics/72/
       /generate_thumbs.php
       

0
 

Author Comment

by:Daniish
ID: 22922331
No error message this time, but still no thumbnails generated.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22922614
dang. ya that script has some issues. I just ran it on my server and it did the thumbs, but they were just black images.

Errrrr. So I guess looking back at your original code, what you have to do is use the dynamic url to the phpthumb script in your media tag. So based on the demo page you had a link for, I guess something like this


<?php
$originals_path = 'includes/travel_pics/72/';
 
if ($handle = opendir($originals_path)) 
{
	while (false !== ($file = readdir($handle))) 
	{
		if ($file != "." && $file != "..") 
		{
			echo "<item><media:thumbnail url=\"http://www.globexposure.net/phpThumb.php?src=$originals_path$file&w=200\"/><media:content url=\"http://www.globexposure.net/$originals_path$file\"/>
			<link>".$originals_path."$file</link>";
		}
		$path = $originals_path."$file";
		$size = getimagesize("$path", $info);
		if(isset($info['APP13'])) 
		{
			$iptc = iptcparse($info['APP13']);
			 
			$datum_j = str_split($iptc['2#055'][0], 4);
			$datum_m_d = str_split($datum_j[1], 2);
			 
			print "<title>$datum_m_d[1]-$datum_m_d[0]-$datum_j[0] - {$iptc['2#120'][0]}</title></item>\n";
		}
		elseif ($file != "." && $file != "..")
		{
			print "<title></title></item>\n";
		}
	}
	 
	closedir($handle);
}
else
{
	print "<p>Error: You're error message. If you use quotes in you're message, put a \ (backslash) before it, others you will get a wide screen.</p>";
}
?>

Open in new window

0
 

Author Comment

by:Daniish
ID: 22922689
I have just realised that when i run your previous script:
http://www.globexposure.net/generate_thumbs.php
it places the thumbnails in the root of my web server - each image has a 'tn_' prefix

When i run your code from your last post:
http://www.globexposure.net/jimjo95.php
I get the following on screen message:
includes/travel_pics/72/Jess and Kate as Devils.jpg  includes/travel_pics/72/Peena and Elaine.jpg  includes/travel_pics/72/Toby Texas Chainsaw Massacre.jpg  includes/travel_pics/72/index.php
0
 

Author Comment

by:Daniish
ID: 22923044
How do i get the thumbnails to save in the correct folder?

Presumably i will need to run the script each time i add new photos to my site?

And lastly, though not really related to my initial question - any idea how i generate a media RSS feed from the each of the folders of thumbnails ?
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22923523
if you run jimjo95.php and view the source in your browser, you'll see that it is in the xml format that your original script was supposed to output. so you can stick with that if you want. You just need all the opening and closing tags. Something like:


<?xml version="1.0" encoding="UTF-8"?>
 
<rdf:RDF
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns="http://purl.org/rss/1.0/"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
 xmlns:admin="http://webns.net/mvcb/"
 xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
>
 
<channel rdf:about="http://www.globexposure.net">
<title>http://www.globexposure.net</title>
<link>http://www.globexposure.net</link>
<description>www.acuitymarketing.com/images/rss.gif</description>
<syn:updatePeriod>hourly</syn:updatePeriod>
<syn:updateBase>1901-01-01T00:00+00:00</syn:updateBase>
<syn:updateFrequency>1</syn:updateFrequency>
<items>
 <rdf:Seq>
  <rdf:li rdf:resource="http://www.globexposure.net/" />
  
 </rdf:Seq>
</items>
</channel>
<?php
$originals_path = 'includes/travel_pics/72/';
 
if ($handle = opendir($originals_path)) 
{
	while (false !== ($file = readdir($handle))) 
	{
		if ($file != "." && $file != "..") 
		{
			echo "<item><media:thumbnail url=\"http://www.globexposure.net/phpThumb.php?src=$originals_path$file&w=200\"/><media:content url=\"http://www.globexposure.net/$originals_path$file\"/>
			<link>".$originals_path."$file</link>";
		}
		$path = $originals_path."$file";
		$size = getimagesize("$path", $info);
		if(isset($info['APP13'])) 
		{
			$iptc = iptcparse($info['APP13']);
			 
			$datum_j = str_split($iptc['2#055'][0], 4);
			$datum_m_d = str_split($datum_j[1], 2);
			 
			echo "<title>$datum_m_d[1]-$datum_m_d[0]-$datum_j[0] - {$iptc['2#120'][0]}</title></item>\n";
		}
		elseif ($file != "." && $file != "..")
		{
			echo "<title></title></item>\n";
		}
	}
	 
	closedir($handle);
}
else
{
	print "<p>Error: You're error message. If you use quotes in you're message, put a \ (backslash) before it, others you will get a wide screen.</p>";
}
?>
</rdf:RDF>

Open in new window

0
 

Author Comment

by:Daniish
ID: 22928831
Nice 1 Jimjo...

When i run your updated script:
http://www.globexposure.net/jimjo95.php

Firebug reports the following errors:
result has no properties
file:///C:/Program%20Files/Mozilla%20Firefox/components/FeedConverter.js
Line 153
this._reader has no properties
file:///C:/Program%20Files/Mozilla%20Firefox/components/FeedProcessor.js
Line 1203

Lastly how do i get the script to pick up all images in the subfolders of 'includes/travel_pics/' ?
E.g. 'includes/travel_pics/72/'
'includes/travel_pics/74/'
'includes/travel_pics/69/'

Thanks again Jimjo
0
 

Author Comment

by:Daniish
ID: 22929014
PicLens expects an RSS file (as below) by default rather than a php script generating RSS XML

I have tried just replacing the 2 references to the following line (from the attached PicLens code template):
feed=http://www.mywebsite.com/photos.rss
with:
feed=http://www.globexposure.net/jimjo95.php

Unfortunately it doesn't seem to recognise our script - is this easily rectifiable or should i open a new question? You've been very helpful so far, i don't want to push my luck LOL

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="760" height="450">
          <param name="movie" value="http://apps.cooliris.com/embed/cooliris.swf" />
          <param name="flashvars" value="feed=http://www.mywebsite.com/photos.rss" />
          <param name="allowFullScreen" value="true" />
          <param name="allowScriptAccess" value="always" />
          
        <!--[if !IE]>-->
          <object id="coolirisSWF" type="application/x-shockwave-flash"
              data="http://apps.cooliris.com/embed/cooliris.swf" width="760" height="450">
            <param name="flashvars" value="feed=http://www.mywebsite.com/photos.rss" />
            <param name="allowFullScreen" value="true" />
            <param name="allowScriptAccess" value="always" />
        <!--<![endif]-->
            <div><p><a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash</a></p></div>
        <!--[if !IE]>-->
          </object>
        <!--<![endif]-->
        </object>

Open in new window

0
 
LVL 6

Expert Comment

by:James Looney
ID: 22929668
Ok I just went through the Piclens (now Cooliris) little wizard for creating a RSS file that works with their system. I've never seen anything quite like this, but it seems reasonable (using a regular expression to match the path to your images).

So, below is the code listing for two different files. The first is photos.rss (this goes in your root directory - probably /www), the second is the code you would put in your web page to load the rss into Cooliris. Let's see if this works, and then if we need to generate thumbs we'll keep pursuing that. :)

//This one is photos.rss - leave out this comment
 
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<cooliris-quick version="1.0">
  <src>^http\:\/\/www\.(.+?)\.(.+?)\/includes\/travel_pics\/72\/(.+?)\.(.+?)$</src>
  <dst>http://www.{1}.{2}/includes/travel_pics/72/{3}.{4}</dst>
</cooliris-quick>
 
 
 
 
 
// This is the embed code for your webpage - leave out this comment
 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="760" height="450">
<param name="movie" value="http://apps.cooliris.com/embed/cooliris.swf" />
<param name="flashvars" value="feed=http://www.globexposure.net/photos.rss" />
<param name="allowFullScreen" value="true" />
<param name="allowScriptAccess" value="always" />
<!--[if !IE]>-->
<object id="coolirisSWF" type="application/x-shockwave-flash" data="http://apps.cooliris.com/embed/cooliris.swf" width="760" height="450">
<param name="flashvars" value="feed=http://www.globexposure.net/photos.rss" />
<param name="allowFullScreen" value="true" />
<param name="allowScriptAccess" value="always" />
<!--<![endif]-->
<div><p><a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash</a></p></div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>

Open in new window

0
 

Author Comment

by:Daniish
ID: 22929821
Excellent. I have uploaded the photos.rss to the root and saved the Cooliris template in a new script:

http://www.globexposure.net/Cooliris.html

- but it doesn't load any images.

0
 
LVL 6

Expert Comment

by:James Looney
ID: 22929850
Well that's frustrating. And the images are definitely in /www/includes/travel_pics/72/ ?
0
 

Author Comment

by:Daniish
ID: 22929934
I have noticed an odd issue - if i visit the images folder:
http://www.globexposure.net/includes/travel_pics/72/

and click on the random blue link thing on the screen - i get the following:

The requested URL /includes/travel_pics/72/includes/travel_pics/72/Peena and Elaine.jpg was not found on this server.

which suggests that it is somehow becoming confused about where it is when it looks for the images (see the duplicated folder structure) - what do you suppose is causing this?

I suspect this is why it's not working but that is just my best guess.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22929973
Ya, that would be the path in a link w/o a leading slash. What is the code in that index page (so much code discussion i can't keep straight which is which)?  :)
0
 

Author Comment

by:Daniish
ID: 22930090
Index.php is my main page index file

Cooliris.html is my demo page that i set up for this question


index.php.txt
Cooliris.html.txt
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22930221
I dont even see what is trying to create those links to the images. are you using some kind of ajax app.? I think this is separate though from the Cooliris problem.

I really don't know what is wrong with the Cooliris page. It's obviously choking on the rss file, but that seems odd since the syntax came from their site.

I guess you can try creating a static xml file, with the names of a couple of your images hardcoded in it. Once you get that working on the Cooliris page you've created, then we can take that syntax and try to make that thumb script work

so, chuck photos.rss and save this as photos.rss and see if Cooliris.html works (may want to take spaces out the filenames of your images - if you do, also take them out of this code

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<item>
		<title>Picture A</title>
		<media:description>Number 1.</media:description>
		<link>includes/travel_pics/72/Jess and Kate as Devils.jpg</link>
		<media:content url="includes/travel_pics/72/Jess and Kate as Devils.jpg"/>
	</item> 
	<item>
		<title>Picture B</title>
		<media:description>Number 2.</media:description>
		<link>includes/travel_pics/72/Peena and Elaine.jpg</link>
		<media:content url="includes/travel_pics/72/Peena and Elaine.jpg"/>
	</item> 
</channel>
</rss>

Open in new window

0
 

Author Comment

by:Daniish
ID: 22930777
At last we have it partially working!

If you run (your code from last post):
http://www.globexposure.net/Cooliris2.html

initially you will see a black screen, BUT if you mouseover the Cooliris display your mouse will discover two hidden images. Clicking on these makes them visible - not sure why they are hidden!


-------------------------------
Just a thought but i've had that funny issue with the random blue thing before, it was caused i think by the Javascript image viewer, Highslide, when the images didn't have the correct tags...but not sure why thats being loaded outside of my index.php page.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22930859
Hehehehhee, nice pictures.  :)

Man this thing is a pain. This is why when my boss asked if we should use Cooliris in our sites, I quickly said "No thanks".

If you truly want the Flash-type slideshow, I might suggest you consider http://slideshowpro.net/. We've used it on several sites and it works well (and is easy to set up).

Or the one I like even better, use the jQuery javascript library and this "thickbox" plugin for jquery. Scroll down to the "Gallery Images" Demo. click one of the images and you can proceed through the images in the "thickbox" popup.
http://jquery.com/demo/thickbox/

Anywho, not sure if we'll get Cooliris working much past this. It might require you posting your page on the Cooliris help forum if you want to for sure use their product.
0
 

Author Comment

by:Daniish
ID: 22931009
Initially i was trying to get my site working with another much better Javascript plugin called Highslide:
http://highslide.com/

Ideally it is this image/thumbnail viewer that i wish to use on my site but at present it won't pick up multiple images on the fly. I was getting help with this from the Highslide community but i was getting impatient with the lack of progress: http://highslide.com/forum/viewtopic.php?t=2600&highlight=

The Cooliris forum is very quiet - but i will post on there again i see if i can't get a little more help.

0
 
LVL 6

Expert Comment

by:James Looney
ID: 22931125
so in that case, you'd just need a script to make the thumbnails for you - then you'd be golden. Let me see if i can get that one script working.
0
 

Author Comment

by:Daniish
ID: 22931128
If we just assume that the images had displayed in the last example -
can we take that syntax and try to make the thumb script work

...coz i feel we are making progress despite the images not displaying but hopefully the Cooliris forum can shed some light on this in due course.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22931250
Ok let's try this one. This you should run to generate the thumbs. create a folder in your "72" folder called "thumbs" so that you have includes/travel_pics/72/thumbs/

by the way, this one will only generate thumbs of jpegs

Once the thumbs are generated, you can either use Highslide as you originally wanted to, or you can modify your photos.rss to include the thumbs:





//put this in a php file and run it to create the thumbs
<?php
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
  // open the directory
  $dir = opendir( $pathToImages );
 
  // loop through it, looking for any/all JPG files:
  while (false !== ($fname = readdir( $dir ))) {
    // parse path for the extension
    $info = pathinfo($pathToImages . $fname);
    // continue only if this is a JPEG image
    if ( strtolower($info['extension']) == 'jpg' )
    {
      echo "Creating thumbnail for {$fname} <br />";
 
      // load image and get image size
      $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
      $width = imagesx( $img );
      $height = imagesy( $img );
 
      // calculate thumbnail size
      $new_width = $thumbWidth;
      $new_height = floor( $height * ( $thumbWidth / $width ) );
 
      // create a new temporary image
      $tmp_img = imagecreatetruecolor( $new_width, $new_height );
 
      // copy and resize old image into new image
      imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
 
      // save thumbnail into a file
      imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
    }
  }
  // close the directory
  closedir( $dir );
}
 
createThumbs("includes/travel_pics/72/","includes/travel_pics/72/thumbs/",100);
?>
 
 
// photos.rss including thumbs
 
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<item>
		<title>Picture A</title>
		<media:description>Number 1.</media:description>
		<link>includes/travel_pics/72/Jess and Kate as Devils.jpg</link>
		<media:content url="includes/travel_pics/72/Jess and Kate as Devils.jpg"/>
               <media:thumbnail url="includes/travel_pics/72thumbs/Jess and Kate as Devils.jpg"/>
	</item> 
	<item>
		<title>Picture B</title>
		<media:description>Number 2.</media:description>
		<link>includes/travel_pics/72/Peena and Elaine.jpg</link>
		<media:content url="includes/travel_pics/72/Peena and Elaine.jpg"/>
                <media:thumbnail url="includes/travel_pics/72/thumbs/Peena and Elaine.jpg"/>
	</item> 
</channel>
</rss>

Open in new window

0
 
LVL 6

Expert Comment

by:James Looney
ID: 22931272
Oh by the way, I just looked at the Highslide demos - that is pretty much the same as Thickbox and thickbox works great. Check the thickbox demo i mention above.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22931296
.....and with thickbox (or highslide) you aren't going to need an RSS file - which you are going to need with Cooliris - meaning your gonna need another script to make the RSS file.
0
 

Author Comment

by:Daniish
ID: 22931380
I had a look at the Thickbox demo and the images seemed to take forever to load and the loading window wasn't particularly glarmorous or slick - so overall i would still prefer Highslide.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22931398
Ok. well if the above thumbnail script works, you can easily use Highslide
0
 

Author Comment

by:Daniish
ID: 22931529
OK the last script of yours successfully generated the thumbnails.

Also when i viewed our slightly older script - it actually displays 1 visible thumbnail - but still not sure why only this one this time lol:
http://www.globexposure.net/Cooliris2.html

...we DO seem to be getting somewhere now LOL
0
 

Author Comment

by:Daniish
ID: 22931540
The thumbnail generator can be seen here:
http://www.globexposure.net/thumb_creator.php
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22931580
K. so look in includes/travel_pics/72/thumbs/ and see if the thumbnails are in there.

If so, let me know if you have trouble with Highslide - though it's installation instructions look pretty straightforward
http://highslide.com/#installation
0
 

Author Comment

by:Daniish
ID: 22931998
Yes the thumbnails are there!

With regards to Highslide, i have managed to get it working with a test site, using a php include and an index file in the respective images folder:
http://www.globexposure.net/example-mini-gallery.php

However, the problems arise trying to get it to work on my main site:
www.globexposure.net/index.php
If you click on the England pushpin marker > Norwich arrow marker > airplane icon - only the first image loads when you click on the thumbnail. Contrast this with the Home icon also in Norwich, where the thumbnail when clicked loads 3 (hard-coded) images that can be cycled thru using Highslides controlbar.

- there seems to be an issue with the php include but not sure what....don't suppose you could shed any light?


Thanks again Jimjo
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22932393
not really sure. i'd have to see all the code
0
 

Author Comment

by:Daniish
ID: 22932699
OK i will list the code/ links here:

The working example site:
http://www.globexposure.net/example-mini-gallery.php
and the index file that the php include uses for this site is (include_index):
http://www.globexposure.net/includes/travel_pics/72/index.php
>>> Incidentally, i have just realised that the presence of this index file meant that it was automatically being picked up when we viewed that folder which resulted in the 'random blue things' - i have since removed it from the folder travel_pics/72/ (but it is still present in the other sub-folders of /travel_pics/)!

My travel site proper is:
www.globexposure.net/index.php
which uses the following script to extract data from MySQL and parse it as XML:
www.globexposure.net/includes/read.php

Please let me know what you think

Once again many thanks for taking the time to investigate this :)
example-mini-gallery.php.txt
index.php.txt
index.php.txt
read.php.txt
0
 

Author Comment

by:Daniish
ID: 22932857
Woohooo i found a typo in the photos.rss file - now that i've corrected it the following example works:
http://www.globexposure.net/Cooliris2.html

So we should be able to make a little more progress with it i hope - that's prob gonna be easier than you wading thru the rest of my code LOL
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22933205
ok. can you post the contents of your rss file so we make sure to include the typo fix that you already did.
0
 

Author Comment

by:Daniish
ID: 22933224

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<item>
		<title>Picture A</title>
		<media:description>Number 1.</media:description>
		<link>includes/travel_pics/72/Jess and Kate as Devils.jpg</link>
		<media:content url="includes/travel_pics/72/Jess and Kate as Devils.jpg"/>
                <media:thumbnail url="includes/travel_pics/72/thumbs/Jess and Kate as Devils.jpg"/>
	</item> 
	<item>
		<title>Picture B</title>
		<media:description>Number 2.</media:description>
		<link>includes/travel_pics/72/Peena and Elaine.jpg</link>
		<media:content url="includes/travel_pics/72/Peena and Elaine.jpg"/>
                <media:thumbnail url="includes/travel_pics/72/thumbs/Peena and Elaine.jpg"/>
	</item> 
</channel>
</rss>

Open in new window

0
 
LVL 6

Expert Comment

by:James Looney
ID: 22933487
Ok here is the thumb script and an rss script combined. so when you add new photos to /72/ just run this script and it should update the rss. you should backup your existing rss file just in case :)

<?php
/*
<item>
	<title>Picture B</title>
	<media:description>Number 2.</media:description>
	<link>includes/travel_pics/72/Peena and Elaine.jpg</link>
	<media:content url="includes/travel_pics/72/Peena and Elaine.jpg"/>
	<media:thumbnail url="includes/travel_pics/72/thumbs/Peena and Elaine.jpg"/>
</item> 
*/
 
$originals_path = 'includes/travel_pics/72/';
 
// adjust the third parameter to the width in pixels you want the thumbs to be
createThumbs($originals_path, $originals_path."thumbs/", 100);
createRSS($originals_path);
 
// END MAIN
 
function createRSS($dir_path)
{
	$fp = fopen('photos.rss', 'w');
	fwrite($fp, '<?xml version="1.0" encoding="utf-8" standalone="yes"?>'."\r".
		'<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom">'."\r".
		'<channel>');
	
	while (false !== ($file = readdir($handle))) 
	{
		if ($file != "." && $file != "..") 
		{
			$title = '';
			$path = $originals_path."$file";
			$size = getimagesize("$path", $info);
			if(isset($info['APP13'])) 
			{
				$iptc = iptcparse($info['APP13']);
				$datum_j = str_split($iptc['2#055'][0], 4);
				$datum_m_d = str_split($datum_j[1], 2);
				$title = "$datum_m_d[1]-$datum_m_d[0]-$datum_j[0] - {$iptc['2#120'][0]}";
			}
			fwrite($fp,  '<item>'."\r".'
				<title>'.$title.'</title>'."\r".'
				<media:description>'.$file.'</media:description>'."\r".'
				<link>'.$dir_path.$file.'</link>'."\r".'
				<media:content url="'.$dir_path.$file.'"/>'."\r".'
				<media:thumbnail url="'.$dir_path.'thumbs/'.$file.'"/>'."\r".'
			</item>'."\r");
		}
	}
	
	fwrite($fp, '</channel>'."\r".'</rss>';
	closedir($handle);
	fclose($fp);
}
 
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
	// open the directory
	$dir = opendir( $pathToImages );
	
	// loop through it, looking for any/all JPG files:
	while (false !== ($fname = readdir( $dir ))) 
	{
		// parse path for the extension
		$info = pathinfo($pathToImages . $fname);
		// continue only if this is a JPEG image
		if ( strtolower($info['extension']) == 'jpg' )
		{
			echo "Creating thumbnail for {$fname} <br />";
			
			// load image and get image size
			$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
			$width = imagesx( $img );
			$height = imagesy( $img );
			
			// calculate thumbnail size
			$new_width = $thumbWidth;
			$new_height = floor( $height * ( $thumbWidth / $width ) );
			
			// create a new temporary image
			$tmp_img = imagecreatetruecolor( $new_width, $new_height );
			
			// copy and resize old image into new image
			imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
			
			// save thumbnail into a file
			imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
		}
	}
	// close the directory
	closedir( $dir );
}
 
 
?>

Open in new window

0
 

Author Comment

by:Daniish
ID: 22934086
I'm a little confused now as to where this script needs to be. I have placed it in the root of my website:
www.globexposure.net/cooliris_rss_builder.php

- is this right? - because it doesn't build the thumbnails!

am i supposed to have a file in the website root also called photos.rss ?

Ultimately i'm hoping to generate an individual RSS file for each sub-folder of includes/travel-pics/ - as these are essentially mini-albums.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22934159
Ya, you should have photos.rss in the web root - which should be there since your cooliris page was working before.

does the new script throw any errors?
0
 

Author Comment

by:Daniish
ID: 22934228
It doesn't throw any errors but, if i delete the thumbnails that we generated earlier using:
http://www.globexposure.net/thumb_creator.php

and then run the new script it doesn't generate any new thumbnails.
0
 

Author Comment

by:Daniish
ID: 22934423
Also the original photos.rss file only had 2 images in it - so when i run the new script it should update this to 3 images to reflect the 3 images that are in both the travel_pics/72 folder (and the travel_pics/72/thumbs folder - when i use the original thumb_creator script) - but this does not happen!

What do you think's going wrong / am i using it the right way?
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22934489
so the new script should go in /www/

and you still have set up
/www/includes/travel_pics/72/
and
/www/includes/travel_pics/72/thumbs/
?

and you have /www/photos.rss ?

Might check permissions on the thumbs folder as well as photos.rss

0
 

Author Comment

by:Daniish
ID: 22934620
Both the www/photos.rss script and the thumbs folder have chmod 755 permissions.

0
 
LVL 6

Expert Comment

by:James Looney
ID: 22934643
change photos.rss to  at least 775 - the www user may not have sufficient privilege to it.

weird that the thumbs worked before, but not now - it's the same code.
0
 

Author Comment

by:Daniish
ID: 22934722
I have updated the privileges but it hasn't made any difference.

I had a look at your last script and perhaps its just my lack of understanding but is this variable properly defined:

$dir_path
0
 

Author Comment

by:Daniish
ID: 22938011
To be honest when it comes to implementing solutions on my server there always seems to be complications - sods law i guess!

Would it be any easier if you had direct access to my server, because i could just back it up and email you the login details...
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22938759
Ya it might.  jrlooney(a)gmail.com - if you feel comfortable doing that.
0
 

Author Comment

by:Daniish
ID: 22938944
As a last resort - yeah i'm quite comfortable with it :p

I have emailed you the relevant details.
0
 
LVL 6

Accepted Solution

by:
James Looney earned 2000 total points
ID: 22939374
Ok. Download a fresh copy of cooliris_rss_builder.php and view it. I left a big comment near the top explaining the parts you can modify in the script for running new photo subalbums. Eventually you are probably going to want to modify  the script a bit so it doesnt run all the time when it doesn't need to etc.

But basically what you want to do is run this script whenever you add new photos - you can run it just once after adding all the photos you want in an album.
0
 

Author Comment

by:Daniish
ID: 22940140
You're an absolute Legend - thank you so much
0
 

Author Closing Comment

by:Daniish
ID: 31514995
Absolutely fabulous - so happy to have it working at last
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month19 days, 21 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question