Urgent --- Saving png image created with php functions

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

Urgent --- Saving png image created with php functions

Post by rav »

Pimptastic | 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 have created png image which inserts the text over the image 
and creates a new image on fly with php image creation functions...

Now, I want to save this text image in the database...

How do i do it as this image is getting created on fly with php image creation functions???

I will appreciate your early reply..

..I am trying to uinsert into database... as follows 

I get data from a form and create text image and then trying to insert 
I can see image with text..but i am not able to insert in database 


Inserting process code....

Code: Select all

<?php 

header("Content-type: image/png"); 

$desc= $_POST['desc']; 

include 'config1.php'; 
include 'opendb.php'; 
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) 
{ 
$fileName = $_FILES['userfile']['name']; 
$tmpName = $_FILES['userfile']['tmp_name']; 
$fileSize = $_FILES['userfile']['size']; 
$fileType = $_FILES['userfile']['type']; 


$fp = fopen($tmpName, 'r'); 


$content = fread($fp, filesize($tmpName)); 

$im = imagecreatefrompng($tmpName); 
$orange = imagecolorallocate($im, 0, 210, 60); 
$px = (imagesx($im) - 7.5 * strlen($desc)) / 2; 
imagestring($im, 3, $px, 9, $desc, $orange); 
imagepng($im); 



$content = addslashes($im); 


fclose($fp); 


if(!get_magic_quotes_gpc()) 
{ 
$fileName = addslashes($fileName); 
} 


$query = "INSERT INTO imgtable (name, size, type, image, description ) VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$desc')"; 

mysql_query($query) or die('Error, query failed'); 
$pid= 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='productAdd.php'>Click here to Enter</a></div>"; 
} 

?>


Thank you
rav


Pimptastic | 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]
Last edited by rav on Wed Aug 09, 2006 8:21 am, edited 1 time in total.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

add a mysql query as its doing the text image and just make it insert it into the database
rav
Forum Newbie
Posts: 5
Joined: Tue Aug 08, 2006 6:57 pm

Post by rav »

Pimptastic | 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]


Yes..I am trying to uinsert into database... as follows

I get data from a form and create text image and then trying to insert
I can see image with text..but i am not able to insert in database and  view this image on view page

Inserting code....

Code: Select all

<?php

header("Content-type: image/png");

$desc= $_POST['desc'];

include 'config1.php';
include 'opendb.php';
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];


$fp      = fopen($tmpName, 'r');


$content = fread($fp, filesize($tmpName));

$im    = imagecreatefrompng($tmpName);
$orange = imagecolorallocate($im, 0, 210, 60);
$px    = (imagesx($im) - 7.5 * strlen($desc)) / 2;
imagestring($im, 3, $px, 9, $desc, $orange);
imagepng($im);



$content = addslashes($im);


fclose($fp);


if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}


$query = "INSERT INTO imgtable (name, size, type, image, description ) VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$desc')";

mysql_query($query) or die('Error, query failed'); 
$pid= 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='productAdd.php'>Click here to Enter</a></div>";
		}

?> 

viewing code
<html>
<head>
<script type="text/javascript">
function lg_bike(MyCode)
{
	var winTop = (screen.height / 2) - 230;
	var winLeft = (screen.width / 2) - 403;
	var windowFeatures = "width=680,height=510,";
	windowFeatures = windowFeatures + "left=" + winLeft + ",";
	windowFeatures = windowFeatures + "top=" + winTop + ",toolbar=no,menubar=no,scrollbars=no,resizable=no,status=no";
	window.open("display.php?id=" + MyCode,"myNewWindow",windowFeatures);
}
</script>
</head>
<body>
<?php



include 'config1.php';
include 'opendb.php';
$query = "SELECT * FROM imgtable order by id" ;
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
} 
else
{

		  

?> 
<table width="700" border="0" cellspacing="0" cellpadding="0">
  
  
  <tr>
    <td colspan="4"><a href="stickyAdd.php">Add Sticky</a> </td>
  </tr>
  <tr>
    <td>Image</td>
    <td>Description</td>
    <td>Edit</td>
    <td>Delete</td>
  </tr>
  <?php
		  while($row = mysql_fetch_array($result))
{
$id =$row['id'];
$size =$row['size'];
$type =$row['type'];
$name =$row['name'];
$image =$row['image'];
$desc =$row['description'];
if ($c==1) {
$bgcolor="#FFFFFF";

} else {
$bgcolor="#F2F2F2";

}


		  

  ?>
  <tr align="left" valign="top" bgcolor="<? echo $bgcolor;  
		  if ($c==0)
		  {
		  $c=1;
		  }
		  else
		  {
		  $c=0;
		  }
		  ?>">
    <td width="175"><a  href="#"><img src="display.php?id=<? echo $id ?>" alt = " Click to see Larger Image" name="image" width="40" class="dec" onClick="lg_bike(<? echo $id ?>)"></a></td>
    <td width="426"><?php echo $desc?></td>
    <td width="50"><a href="stickyEdit.php?id=<? echo $id?>">Edit</a></td>
    <td width="49"><a href="stickyDelete.php?id=<? echo $id?>">Delete</a></td>
  </tr>
  <?php
}
  ?>
</table>
  <?php
}
  ?>
  </body>
  </html>

Pimptastic | 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]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

How is this urgent? :?
Post Reply