Jump to content

Archived

This topic is now archived and is closed to further replies.

rav

Editing database Image

Recommended Posts

Hello:
I need to open an image from database to edit...

and witre text on it with php functions (text is being sent from a form on edit page)
and then I need it to be saved with different name in database...

I am not able to get image data and not sure how to get it???--(Currently, I am passing data with varables(they hold values of type, size, name, and image) in edit page to this process page)

Can any one help me in this please??
I will appreciate your help..
thank you
[code]
<?php
function ImageStringWrap($image, $font, $x, $y, $text, $color, $Text_Size, $maxwidth, $height, $subWidth, $subHeight, $align)
{
$fontwidth = imagefontwidth($Text_Size);
$fontheight = imagefontheight($Text_Size);
$maxlines = floor($height /$fontheight)-$subHeight;
if ($maxwidth != NULL)
{
$maxcharsperline = floor($maxwidth/ $fontwidth) -$subWidth ;
}
for ($i=0; $i < sizeof($text); $i++)
{
$Text_Box_Size = imagettfbbox($Text_Size, 0, $font, "MXQJPmxqjp123");
$Text_Box_Width = abs($Text_Box_Size[2]) + abs($Text_Box_Size[0]);
$Text_Box_Height = abs($Text_Box_Size[7] + $Text_Box_Size[1]);
$Text_Height = $Text_Height + $Text_Box_Height;

if ($align="l")
{
$posx = $x;
$posy = $y;
}

$text = wordwrap($text, $maxcharsperline, "\n", 1);
$lines = explode("\n", $text);

foreach($lines as $lines)
{
imagettftext($image, $Text_Size, 0, $posx, $posy, $color, $font, $lines);
$posy+= $fontheight+10;
//$y += $fontheight +10;
}

}

}

?>
<?php

header("Content-type: image/png");
$id = $_POST['id'];
$desc= $_POST['desc'];

$name= $_POST['name'];
$image= $_REQUEST['image'];
$type= $_REQUEST['type'];
$size= $_REQUEST['size'];

$x=$_POST['x'];
$y=$_POST['y'];
$subWidth = $_POST['subWidth'];
$subHeight = $_POST['subHeight'];

$font = $_POST['font1'];//'font/arial.ttf';
$fontsize=$_POST['fontsize1'];//18;

$r=$_POST['r'];
$g=$_POST['g'];
$b=$_POST['b'];

$xLocPg=$_POST['xLoxPg'];
$yLocPg=$_POST['yLocPg'];

include 'config1.php';
include 'opendb.php';




$im= imagecreatefrompng($image);

$textcolor = imagecolorallocate($im, $r, $g, $b);

$imWide=imagesx($im);

$imHeight = imagesy($im);


ImageStringWrap($im, $font, $x, $y, $desc, $textcolor, $fontsize, $imWide, $imHeight,$subWidth, $subHeight,"l" );


imageSaveAlpha($im, true);
ImageAlphaBlending($im, false);

$outfile= "${id}.png";
imagepng ($im, $outfile);
$size1 = filesize($im);


if($outfile>0)
{


$fp1 = fopen($outfile, 'r');
$content1 = fread($fp1, filesize($outfile));
$content1 = addslashes($content1);

$size1 = filesize($outfile);
fclose($fp1);

$query = ("update imgtable set image1 = '$content1', type1 = '$type', size1 = '$size1', name1 = '$tgtFile', description = '$desc', x='$x', y='$y', font='$font', fontsize='$fontsize', r='$r', g='$g', b='$b', subWidth='$subWidth', subHeight='$subHeight', xLocPg='$xLocPg', yLocPg='$yLocPg' where id='$id'")or die("Couldn't update query, the ID was '$pid'<br>\n".mysql_error());

mysql_query($query) or die('Error, query failed');
$id= mysql_insert_id();
echo " <div align='center'>You have successfully added the Image! <a href='stickyView.php'>Click here to view</a></div>";

imagedestroy($im);

}

else
{
echo "<div align='center'>Please enter full record. <a href='stickyView.php'>Click here to Enter</a></div>";
echo "<br> $maxlines";
}


?>
[/code]

Share this post


Link to post
Share on other sites
Post [b]ONCE[/b] in the most appropriate forum. Don't spam us. Your other posts will be deleted.

And to make your code readable, wrap code tags around, please.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.