free
This is our archive, please go to the main forum page for the latest discussions and news about free web hosting.


PHP Email Image

iBrightDev
November 27th, 2007, 16:45
# email.php
// EMAIL IMAGE
define("F_SIZE", 10);
define("F_ANGLE", 0);
define("F_FONT", "verdana_0.ttf");

$text = "email@domain.com";

$Leading=0;
$W=0;
$H=0;
$X=0;
$Y=0;
$_bx = imagettfbbox(F_SIZE, F_ANGLE, F_FONT, $text);
$s = split("[\n]+", $text); // Array of lines
$nL = count($s); // Number of lines

$W = ($W==0)?abs($_bx[2]-$_bx[0]):$W;
$H = ($H==0)?abs($_bx[5]-$_bx[3])+2+($nL>1?($nL*$Leading):0):$H;

$img = @imagecreate($W, $H) or die("Cannot Initialize new GD image stream");

$white = imagecolorallocate($img, 255,255,255);
$txtColor = imagecolorallocate($img, 55,103,122);

$alpha = range("a", "z");
$alpha = $alpha.strtoupper($alpha).range(0, 9);

// Use the string to determine the height of a line
$_b = imageTTFBbox(F_SIZE, F_ANGLE, F_FONT, $alpha);
$_H = abs($_b[5]-$_b[3]);
$__H = 0;

// Use the string to determine the width of a line
$_b = imagettfbbox(F_SIZE, F_ANGLE, F_FONT, $text);
$_W = abs($_b[2]-$_b[0]);

// Final width and height
$_X = abs($W/2)-abs($_W/2);
$__H += $_H;

imagettftext($img, F_SIZE, F_ANGLE, $_X, $__H, $txtColor, F_FONT, $text);

header("Content-Type: image/png");
imagepng($img);
imagedestroy($img);

// END EMAIL IMAGE


then use a simple image tag to call the image on a normal php page like so...


<img src="email.php" />

Mentok
November 29th, 2007, 13:09
Took me a minute to figure out what you meant but yeah that looks cool :) Would +rep you but can't :(

iBrightDev
November 29th, 2007, 13:21
if it is confusing at all, go here to see an example...
http://www.azbizfilings.com/includes/email.php

Mentok
November 29th, 2007, 16:11
ie this bit:
http://www.azbizfilings.com/includes/email.php
Narrow it down more Justin ;)

iBrightDev
November 29th, 2007, 17:18
ie this bit:
http://www.azbizfilings.com/includes/email.php
Narrow it down more Justin ;)

it was narrowed down to less to begin with, but, since the size of the image is set automatically depending on the font size, font type and the characters, it required a little extra code to do that. ;)

Mentok
November 29th, 2007, 17:25
No.. I meant narrow down the example.. as in link to the image rather than a page with lots of different things on it.

The script size itself is perfectly fine :p

iBrightDev
November 29th, 2007, 17:55
oh, lol, didnt realize you meant that. haha. done :D

hm3cs
December 29th, 2007, 08:23
oh, lol, didnt realize you meant that. haha. done :D

Thank you verry much :-)

Doolvehek
December 18th, 2009, 01:15
I think it would be better if _SERVERPHP_SELF was used instead of _SERVERREQUEST_URI

_SERVERREQUEST_URI wont identify the page if there is a query string in the URL example index.php?action=something

PHP Code:
<?php

if _SERVERPHP_SELF == /about.php

// if page = about.php show this image
echo <img src=pathofimg />;

else if _SERVERPHP_SELF == /contact.php

// if page = contact.php show this image
echo <img src=pathofimg />;

else

// for all other pages show this image
echo <img src=pathofimg />;



?>
Not tested, but should work.

iBrightDev
January 27th, 2010, 13:19
I think it would be better if _SERVERPHP_SELF was used instead of _SERVERREQUEST_URI

_SERVERREQUEST_URI wont identify the page if there is a query string in the URL example index.php?action=something

PHP Code:
<?php

if _SERVERPHP_SELF == /about.php

// if page = about.php show this image
echo <img src=pathofimg />;

else if _SERVERPHP_SELF == /contact.php

// if page = contact.php show this image
echo <img src=pathofimg />;

else

// for all other pages show this image
echo <img src=pathofimg />;



?>
Not tested, but should work.

wtf are you talking about? _SERVERREQUEST_URI was never used. i also never said anything about needing to determine the page you are on.





  
  News · Search free hosts · Free file hosting · Free image hosting · Reviews · Forums · Related Links · Advertising Info · Contact Us


Copyright © 1996-2008 Per Olof Sandholm. All rights reserved. Privacy Statement

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum