Page 1 of 1
ImageString - Multiple Lines
Posted: Sat Aug 16, 2003 4:56 pm
by Pineriver
Hi, everyone. I have searched on the web and I haven't come up with anything. I have a text area for users to type in what should be displayed on the image generated by ImageString. Now I want the text area to have it so users can display multiple lines of text on the image like...
Line1
Line2
Line3
But every time I use the variable that is outputting the text into the ImageString, it
is all one line and there is <br> where the line is supost to end. I have heard that the ImageTTF can to lines like this, but you have to install something like FreeType. My question is, is there a way to have multi lines using ImageString? and can I install FreeType on my web server account even if I am not the host of the account?
Thanks in Advance
Posted: Sat Aug 16, 2003 9:28 pm
by Kriek
Use \n (new-line character)
Posted: Sun Aug 17, 2003 5:37 pm
by Pineriver
Thanks, but when I try to put a "\n" where the lines should go, there is the "\n" and in little letters "V/T" on one line on the image, I tried other scripts but no success
Posted: Mon Aug 18, 2003 4:16 am
by twigletmac
Could we see your code?
Mac
Posted: Mon Aug 18, 2003 9:32 am
by Pineriver
Code: Select all
<?
$DocRoot='./';
$aPics = array(
"http://www.solarisdx.net/pineriver/testing/nopic.jpg",
);
$i = time(3) % sizeof($aPics);
$urls = $aPics[$i];
Header ('Content-type: image/jpeg');
Header ('Content-Disposition: attachment; filename="pic.jpg"');
$filenamecolor = "color.txt";
$filenamesize = "text_size.txt";
$prossimage = "$urls";
$filename = "file.txt";
$message = implode('',file($filename));
$text_color = implode('',file($filenamecolor));
$text_size = implode('',file($filenamesize));
# standard height & weight if not given
if(!isset($maxX)) $maxX = 256;
if(!isset($maxY)) $maxY = 256;
# colour- & textvalues
$picBG = "0,0,0"; # RGB-value !
$picFG = "$text_color"; # RGB-value !///this line changes color
$copyright = "$message";
$font = $text_size;
# minimal & maximum zoom
$minZoom = 1; # per cent related on orginal (!=0)
$maxZoom = 200; # per cent related on orginal (!=0)
# paths
$imgpath = ""; # ending with "" !
$nopicurl = "$prossimage"; # starting in $imagepath!!!
$nofileurl = "$prossimage"; # starting in $imagepath!!!
if(!isset($image) || empty($image))
$imageurl = $imgpath . $nopicurl;
elseif(! file_exists($imgpath . trim($image)))
$imageurl = $imgpath . $nofileurl;
else
$imageurl = $imgpath . trim($image);
# reading image
$image = getImageSize($imageurl, $info); # $info, only to handle problems with earlier php versions...
switch($image[2]) {
case 1:
# GIF image
$timg = imageCreateFromGIF($imageurl);
break;
case 2:
# JPEG image
$timg = imageCreateFromJPEG($imageurl);
break;
case 3:
# PNG image
$timg = imageCreateFromPNG($imageurl);
break;
}
# reading image sizes
$imgX = $image[0];
$imgY = $image[1];
# calculation zoom factor
$_X = $imgX/$maxX * 100;
$_Y = $imgY/$maxY * 100;
# selecting correct zoom factor, so that the image always keeps in the given format
# no matter if it is more higher than wider or the other way around
if((100-$_X) < (100-$_Y)) $_K = $_X;
else $_K = $_Y;
# zoom check to the original
if($_K > 10000/$minZoom) $_K = 10000/$minZoom;
if($_K < 10000/$maxZoom) $_K = 10000/$maxZoom;
# calculate new image sizes
$newX = $imgX/$_K * 100;
$newY = $imgY/$_K * 100;
# set start positoin of the image
# always centered
$posX = ($maxX-$newX) / 2;
$posY = ($maxY-$newY) / 2;
# creating new image with given sizes
$imgh = imageCreateTrueColor($maxX, $maxY);
# setting colours
$cols = explode(",", $picBG);
$bgcol = imageColorallocate($imgh, trim($cols[0]), trim($cols[1]), trim($cols[2]));
$cols = explode(",", $picFG);
$fgcol = imageColorallocate($imgh, trim($cols[0]), trim($cols[1]), trim($cols[2]));
# fill background
imageFill($imgh, 0, 0, $bgcol);
# create small copy of the image
imageCopyResampled($imgh, $timg, $posX, $posY, 0, 0, $newX, $newY, $image[0], $image[1]);
# writing copyright note
imageString($imgh, $font, $maxX-250, $maxY-31, $copyright, $fgcol);
# output
switch($image[2]) {
case 1:
# GIF image
header("Content-type: image/gif");
imageGIF($imgh);
case 2:
# JPEG image
header("Content-type: image/jpeg");
imageJPEG($imgh);
case 3:
# PNG image
header("Content-type: image/png");
imagePNG($imgh);
}
# cleaning cache
imageDestroy($timg);
imageDestroy($imgh);
?>
I have variables for the color, font and text, since my server dosent support databases, I use text files.