/    Sign up×
Community /Pin to ProfileBookmark

Help with imagecreate…

Hello,

I wrote a web counter in php that displays text and images. What I am now trying to do is to convert the output of this php script in an image. Why? Because certain blogs like MSN Spaces do not accept that you embed scripts.

I believe I should look into the imagecreate function for a solution, but I find very little examples of how to use it, expecially imagecreatefromgd2 and the likes. Ideally I would need a function that allows me to input a URL (like my php script) and that ouputs an image.

Perhpas someone can help me with this?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@bokehJul 27.2006 — Where is the count coming from?

Here's a very basic GD function:[code=php]function Str2Img($input)
{
$fontsize = 5;
$length = strlen($input);
$image = imagecreate(($length*imagefontwidth($fontsize))+1, imagefontheight($fontsize)+1);
$background_colour = imagecolorallocate($image, 255,255,255);
$text_shadow = imagecolorallocate($image, 127,127,127);
$text_colour = imagecolorallocate($image, 0,0,0);
imagestring($image, $fontsize, 1, 1, $input, $text_shadow);
imagestring($image, $fontsize, 0, 0, $input, $text_colour);
header ('Content-type: image/png');
imagepng($image);
imagedestroy($image);

die;
}[/code]
Copy linkTweet thisAlerts:
@cameraguyauthorJul 28.2006 — Thanks, but that's the string-to-image script using the very basic imagecreate function that is available everywhere. I am looking for help with the other functions like imagecreatefromgd2, imagecreatefrombmx ,etc... in particular the one that creates an image out of a a url input.
Copy linkTweet thisAlerts:
@bokehJul 28.2006 — string-to-image script... very basic... available everywhere. I am looking for help with the other functions... in particular one that creates an image out of a a url input.[/QUOTE]Maybe it's not exactly what you wanted but it certainly does that.[code=php]Str2Img($_GET['counter_value']);[/code]

The best thing would be to create what you have in mind with photoshop and then post it here. If you don't want to use the built-in font you could create ten images (corresponding to 0 thru 9) and have gd stitch them. Pretty simple stuff for someone that knows the GD functions.
Copy linkTweet thisAlerts:
@cameraguyauthorJul 28.2006 — Thanks bokeh. Here is what I am now displaying through a php script:

[URL=http://capucine.speich.free.fr/counter.gif]counter[/URL]

It's made of several flag images and text strings. It's embeded in web pages like this:

<script language="javascript" src="http://...counter.php?user=12345"></script>

But since more and more blog providers (like MSN Spaces) do not allow javascript in their blogs, I need to change the way I embed the counter. I noticed other counter providers conver their counters in an image, which then can be easily ebedded in script-unfriendly blog.

Thanks for any help you can provide.
Copy linkTweet thisAlerts:
@bokehJul 28.2006 — Have you got a link that is not in image form so I can see the javascript? It's pretty simple to create but you are going to need an IP database for a start.
Copy linkTweet thisAlerts:
@cameraguyauthorJul 29.2006 — I managed to achieve what I was looking for. I ended up using :

*imagecreate

*
imagestring (to write he name of the country)

*imagecreatefromgif (to add the flag of the country)

*
imagegif

*imagedestroy

But I noticed that "imagecopymerge" slows down the script enormously. Is this to be expected?
Copy linkTweet thisAlerts:
@bokehJul 29.2006 — Can I see your output?
×

Success!

Help @cameraguy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...