/    Sign up×
Community /Pin to ProfileBookmark

Image manipulation Help

I am a newbie playing around with PHP’s image manipulation scripts. I am trying to get PHP to intergrate with html. The code below is supposed to create an image with text on it. The code works great without any html. e.g. if I have just <?php …. to ?>. However, when I add html it converts the image into “text”, not really what I am looking for.

What am I doing wrong? I assume that PHP can be placed anywhere in the <body> of an html document. FYI, I am using Apache 2.0.54 and PHP 5.0.4. Is there something I need to modify in the config file or .ini file to get this to work?

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
$image = imagecreatefromjpeg(“smp.jpg”);
$text=”test”;
$font=”arial.ttf”;
$fontsize=25;

//choose textcolors (black & white), shadow effect
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);

//check width of the text
$bbox=imagettfbbox ($fontsize, 0, $font, $text);
$xcorr=0-$bbox[6];
$mase=$bbox[2]+$xcorr;

//check width of the image
$width=imagesx($image);

//calculate x coordinates for text
$new=($width-$mase)/2;

//write text
imagettftext ($image, $fontsize, 0, $new-4, 60, $black, $font, $text);
imagettftext($image, $fontsize, 0, $new, 60, $white, $font, $text);

//output picture
imagejpeg($image,””,100);
imagedestroy($image);
?>
</body>
</html>

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @evolt 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...