natatkinson
10-10-2008, 11:31 AM
Here is my code
if ($type == 'image/jpeg') {
$new_image = imagecreatefromjpeg ($base_image);
$text_colour = imagecolorallocate( $new_image, 255, 255, 255 );
$line_colour = imagecolorallocate( $new_image, 128, 255, 0 );
$imagestring( $new_image, 2, 30, 25, $details, $text_colour );
header('Content-type: image/jpeg');
imagejpeg( $new_image );
}
$details contains text passed from a form, and when I run this script I get this error:
Fatal error: Function name must be a string in /home/nate/domains/eiurunning.com/public_html/runnion/image_create_sub.php on line 137
Any help would be greatly appreciated. I'm just trying to add some text to a picture, and output it.
natatkinson
10-10-2008, 01:05 PM
Alright, I already saw my bonehead mistake there. So problem fixed.
But my next question, and I've had trouble finding anything by googling, is placing another image within an image by the php imagecreate.
ariell
10-11-2008, 07:05 PM
The code below is a command line tool that I programmed to manipulate images. It certainly must be tailored for individual purposes. However, if you go over the code you'll get the idea how to copy/re-sample and so on images using GD.
<?php // /_tools/xic/overlay/tab_lines_partofbg.php
$imgpath = '../../../img/bg/';
// image usage name
$usagename = 'bg'; // background
if (@$_GET['un'])
$usagename = $_GET['un'];
// corename for image
$corename = 'ovl'; // overlay
if (@$_GET['cn'])
$corename = $_GET['cn'];
// spectrum name
$specname = 'tab'; // table
if (@$_GET['sn'])
$specname = $_GET['sn'];
// source image dimensions, X1
$startXOverlay = 200; // relative to X1(sizeX)
if (@$_GET['sox'])
$startXOverlay = $_GET['sox'];
// source image dimensions, Y1
$startYOverlay = 5; // relative to Y1(sizeY)
if (@$_GET['soy'])
$startYOverlay = $_GET['soy'];
// new image dimensions, X1
$sizeX = 640;
if (@$_GET['w'])
$sizeX = $_GET['w'];
// new image dimensions, Y1
$sizeY = 350;
if (@$_GET['h'])
$sizeY = $_GET['h'];
// figutive "level" to qualify a number
// (to define the distance between vertical lines in the grid)
$units = 0;
if (@$_GET['u'])
$units = $_GET['u'];
// transparancy
$opacity = 70; // 0 = 100% opaque, 127 = 100% transaparent
if (@$_GET['o'])
$opacity = $_GET['o'];
// color
$RGB = array(127,127,192);
if (@$_GET['rgb']) {
$t = explode('-', $_GET['rgb']);
for ($i=0; $i < count($t); $i++)
$RGB[$i] = $t[$i];
} // RGB passed
$bgFile = 'bg_cspace3_blended.png';
if (@$_GET['bgfile'])
$bgFile = $_GET['bgfile'];
// generate an appropriate file name
// @TODO define rules
$newfile = $imgpath.'.'.$usagename.'.'.$corename.'.'.$specname.'-'; // corepart of ilename
$newfile .= 'sox_'.$startXOverlay.'.soy_'.$startYOverlay.'.w_'.$sizeX.'.h_'.$sizeY.'.u_'.$units.'.o_'.$opacity;
$newfile .= '.png';
// create canvas
$img = imagecreatetruecolor($sizeX,$sizeY);
imageantialias($img, true);
imagealphablending($img, true);
// bg image (underneath overlay)
$bgFile = $imgpath.$bgFile;
$bgImage = imagecreatefrompng($bgFile);
$dim = getimagesize($bgFile);
// calculate prospective remainings
// total width BG image - space between start and OVERLAY start - overlay total width
$sizeXRemaining = ($dim[0] - $startXOverlay - $sizeX);
// total height BG image - space between start and OVERLAY start - overlay total height
$sizeYRemaining = ($dim[1] - $startYOverlay - $sizeY);
// copy PART of image read from file onto destination image (the blend)
imagecopyresized(
/*destination image*/ $img,
/*source image*/ $bgImage,
/*destination coords*/ 0, 0,
/*source STARTING coords*/ $startXOverlay, $startYOverlay,
/*destination lengths*/ $sizeX, $sizeY,
/*source lengths*/ $sizeX, $sizeY
);
// draw the blueish areas ion the background image
// one for the chart, one for the title
$background = imagecolorallocatealpha(
/*resource image*/ $img,
/*R*/ $RGB[0],
/*G*/ $RGB[1],
/*B*/ $RGB[2],
/*alpha*/ $opacity
);
// the actual tab
imagefilledrectangle(
/*resource image*/ $img,
/*coords*/ 20, 20,
($sizeX - 20), ($sizeY - 20),
/*(background-)color*/ $background
);
if ($units > 0) { // grid
// the grid...
// color every second line black, the others grey
// define a color for "ONE" and "THEOTHER"
$linecolor1 = imagecolorallocate($img, 149, 160, 151);
$linecolor2 = imagecolorallocate($img, 138, 138, 138);
// get some cushion rules for our table
// figutive maximum on a 100 percent basis
// NOTE: UNITS stands for a picture line, thus 1/1000 px
$maxValue = 8000; // NORMAL (LINES) TABLE
//$maxValue = ($sizeY*1000); // RASTERED BG (-ONLY) TABLE, the more units, the more rastered
for ($i=$units; $i < $maxValue; $i += $units) {
$x1 = 40;
/*
* the more space you need UNDER the table lines, but WITHIN the image,
* the more you need to increase $y1, i.e.:
* $y1 = ( ($sizeY - 120 - ( ($i / $maxValue) * ($sizeY - 160) ) ) );
* ... and you have pleanty of space for a BOLD explanation on what you show on the image,
* for instance, a GRAPH
*/
$y1 = ( ($sizeY - 80 - ( ($i / $maxValue) * ($sizeY - 120) ) ) );
$x2 = ($sizeX - 40);
$y2 = $y1; // take ($sizeY-40) and you have a falling gradiant!
// draw a graphical LINE
imageline(
/*resource image*/ $img,
/*coords*/ $x1, $y1, $x2, $y2,
/*color*/ ($i % (2 * $units)) == 0 ? $linecolor1 : $linecolor2
);
} // all units
} // grid
// flush to browser
header('Content-type: image/png');
if (@$_GET['file'] != '') { // supposed to be written to disk
if (@$_GET['file']=== '1') { // use pre-formed name
$filename = $newfile;
} // use pre-formed name
else { // use passed name
$filename = $imgpath.$_GET['file'].'.png';
} // use passed name
imagepng($img, $filename, 7, NULL);
} // supposed to be written to disk
imagepng($img);
?>
We had a posting few days ago with a similar question, so, this is the SAME code.
Best from the south.
natatkinson
10-12-2008, 08:59 AM
Thank you very much for the reply. I looked up the php imagecopy() and got it working. thank you for the code, it got me thinking, and know i've got it woring.
ariell
10-12-2008, 10:16 AM
A Pleasure. As I said, the code was just to give you an idea.
It is very recommendable to sort out the important stuff from those GD 10-parms-monster-functions and making a class of what one really needs.
Best from the south.