Edit Image from mysql database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rav
Forum Newbie
Posts: 5
Joined: Tue Aug 08, 2006 6:57 pm

Edit Image from mysql database

Post by rav »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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: Select all

<?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";
		}


?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply