ConFoo Montreal 2026: Call for Papers

Voting

: min(nine, two)?
(Example: nine)

The Note You're Voting On

Epidemiah
17 years ago
Its just an easy function to write an string in the middle of a picture.

<?php

function imageCenterString(&$img, $font, $text, $color)
{
if(
$font < 0 || $font > 5){ $font = 0; }
$num = array(array(4.6, 6),
array(
4.6, 6),
array(
5.6, 12),
array(
6.5, 12),
array(
7.6, 16),
array(
8.5, 16));
$width = ceil(strlen($text) * $num[$font][0]);
$x = imagesx($img) - $width - 8;
$y = Imagesy($img) - ($num[$font][1] + 2);
imagestring($img, $font, $x/2, $y/2, $text, $color);
}

?>

<< Back to user notes page

To Top