| | |
Need help making simple random images
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
I am having trouble figuring this out as I am only a beginner.
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.
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
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 !
•
•
•
•
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.
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...
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
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
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.
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
•
•
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
[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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Other Threads in the PHP Forum
- Previous Thread: apache2-devel file?
- Next Thread: Making a phpbb installer like fantastico
| Thread Tools | Search this Thread |
301 ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dynamic echo email eregi error execution file files folder foreach form forms function functions google href htaccess html httppost image include insert integration ip java javascript joomla library limit link links login loop mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem query radio random recursion regex remote script search searchbox server session sessions sms soap source space sql syntax system table tutorial update upload url validator variable video volume votedown web website xml youtube zend






