Need help making simple random images

Reply

Join Date: Jul 2006
Posts: 174
Reputation: tefflox is an unknown quantity at this point 
Solved Threads: 1
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Need help making simple random images

 
0
  #1
Nov 8th, 2006
Hello, will you help me write some code to generate random-colored ellipses for an html page? The ellipses will serve as a side-bar coloration for the regular text content. Each successive image will have an increasing z-index and will overlap each other.

I am having trouble figuring this out as I am only a beginner.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Need help making simple random images

 
0
  #2
Nov 9th, 2006
Hi,

Take a look at PHP's GD functions:
http://us3.php.net/gd

You'll need the imagepolygon function, http://us3.php.net/manual/en/function.imagepolygon.php, to create your ellipses.

Last edited by digital-ether; Nov 9th, 2006 at 3:18 pm.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 174
Reputation: tefflox is an unknown quantity at this point 
Solved Threads: 1
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Re: Need help making simple random images

 
0
  #3
Nov 9th, 2006
hello again.. you were interested in learning java, i recall. thanks for help here.. i'm a big dreamer, accomplish little.. i actually want to retrieve random images from google searches now, but i've settled for the effect so far: http://listenlight.net/04. I have left ample space 'neath the texts for another design implementation.. cheers.. hope you like the poems.. I'm JC, there, and co-editor. i'm feeling terribly proud right now !

Originally Posted by digital-ether View Post
Hi,

Take a look at PHP's GD functions:
http://us3.php.net/gd

You'll need the imagepolygon function, http://us3.php.net/manual/en/function.imagepolygon.php, to create your ellipses.

Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Need help making simple random images

 
0
  #4
Nov 9th, 2006
Yep, I'm still on the quest to learn java.. lol.

As for using random googel images, I think it would be easier to use images from flickr. They have RSS feeds for images categorized by tags. Its much easier to use RSS feeds then to parse a google search HTML page, or get images using the Google Soap API.

Flickr even allows a format for serialized PHP or just plain PHP!

Example URL:

http://api.flickr.com/services/feeds...ful&format=php

That returns all images for the tags: "colorful" in a PHP array named $feed. The array is structured like an RSS document where $feed['items'] contains each feed item..

So you could use it like:

[php]// includes the images from flickr for the comma seperated $tags
$tags = urlencode('colorful');
include( "http://api.flickr.com/services/feeds/photos_public.gne?tags=$tags&format=php" );


foreach($feed['items'] as $item) {
echo $item['description'];
}
[/php]

too simple huh...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Need help making simple random images

 
0
  #5
Nov 9th, 2006
Your site design is quite unique by the way... congrats!
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 174
Reputation: tefflox is an unknown quantity at this point 
Solved Threads: 1
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Re: Need help making simple random images

 
0
  #6
Nov 9th, 2006
awesome! thanks

i just ran your code and the task suddenly seems within reach.
Last edited by tefflox; Nov 9th, 2006 at 5:14 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 174
Reputation: tefflox is an unknown quantity at this point 
Solved Threads: 1
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Re: Need help making simple random images

 
0
  #7
Nov 9th, 2006
how do i parse out the "<img src... />" strings ? now i'm excited. all i really know of php are the random and array functions
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 174
Reputation: tefflox is an unknown quantity at this point 
Solved Threads: 1
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Re: Need help making simple random images

 
0
  #8
Nov 9th, 2006
it works fine on my localhost, but on the hosting server i get these errors.

Warning:  include() [function.include]: URL file-access is disabled in the server configuration in /home/.highjump/tefflox/listenlight.net/flickr.php on line 13

Warning:  include(http://api.flickr.com/services/feeds...ful&format=php) [function.include]: failed to open stream: no suitable wrapper could be found in /home/.highjump/tefflox/listenlight.net/flickr.php on line 13

Warning:  include() [function.include]: Failed opening 'http://api.flickr.com/services/feeds/photos_public.gne?tags=colorful&format=php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/.highjump/tefflox/listenlight.net/flickr.php on line 13

Warning:  Invalid argument supplied for foreach() in /home/.highjump/tefflox/listenlight.net/flickr.php on line 15

Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Need help making simple random images

 
0
  #9
Nov 10th, 2006
It looks like the allow_url_fopen setting has disabled in PHP.ini. You cannot change this setting at runtime, you will have to edit PHP.ini.

see: http://us3.php.net/filesystem

If you can't edit PHP.ini then you will have to contact your web host 'bout it, or use CURL.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Need help making simple random images

 
0
  #10
Nov 10th, 2006
Originally Posted by tefflox View Post
how do i parse out the "<img src... />" strings ? now i'm excited. all i really know of php are the random and array functions
For that you can use Regex.
[PHP]if (preg_match("/<img src=\"([^\"]+)\" .*? alt=\"([^\"]+)\" .*? \/>/", $item['description'], $matches)) {
$img_html = $matches[0];
$img_src = $matches[1];
$img_title = $matches[2];

// ouput image

}[/PHP]

I thought I'd take the time to explain the regex:

I used the function preg_match, which takes a regular expression (string pattern) and matches the pattern in the $item['description'] string.
The matches are set as an array in the third parameter, in this case $matches.

Heres the regex expression:
"/<img src=\"([^\"]+)\" .*? alt=\"([^\"]+)\" .*? \/>/"

It is quite simple:
a regext expression starts with a delimiter, in this case /. When the regex engine finds another instance of / it will end the pattern and assume every character after the second delimiter are arguments passed with the regex expression.

$matches[0] will contain a match of the whole pattern (if a match is made).
$matches[1] contains a matche of the first set of parantheses () and so on.

square brackets allow you to match any character inside the brackets.
^ right after the first square bracket tells the regex engine to match any char other than whats in the square brackets.

. is any single character.
* is any number of the character right before it.
+ is one or more of the chracter right before it.
\ is used to escape characters, meaning the character right after the \ is treated as a literal value and does not have any special meaning. eg: \* means match the asterix itself.
? means either or? or 0 or 1 of the character right before it. If it is placed right after a quantifier eg: .*? then it tells the regex engine to match "lazily" - match the smallest possible match, as opposed to matching "greedily" where the largest match is made. eg: In "<tag> cotent </tag>", the regex "<.*>" will match the whole string, however, "<.*?>" will only match "<tag>".

So the regex expression "/<img src=\"([^\"]+)\" .*? alt=\"([^\"]+)\" .*? \/>/" reads:

<img src=\" : Matche a string starting with <img src="
([^\"]+) : create a new match in $matches[1] and match all the chracters that aren't a double quote, ".
.*? continue matching any character (lazily) untill you come to: alt=
alt=\" : match alt="
([^\"]+) : create a new match in $matches[2] and match all the chracters that aren't a "
.*? \/> : match any chracter (lazily) till you reach />

Now you get a resulting array: $matches with the tree matches inside. $matches[0] being the whole string. $matches[1] being the first ([^\"]+) and $matches[2] being the second ([^\"]+)
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC