Use/get default image from server if no file is uploaded - php

Hi i have a form which ask the user to upload photo. is uses the photo as second image(image on top of another) in imagecreatefromjpg and imagecopyresampled. but it seems like the uploaded image is not being get properly. also the default image is not passed from the server when no file is uploaded. im getting these errors:
Warning</b>: imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: Filename cannot be empty in <b>/home/content/52/12096052/html/Testupdate/processor.php</b> on line <b>117</b>
Warning</b>: imagesx() expects parameter 1 to be resource, boolean given in <b>/home/content/52/12096052/html/Testupdate/processor.php</b> on line <b>145</b><br />
Warning</b>: imagesy() expects parameter 1 to be resource, boolean given in /home/content/52/12096052/html/Testupdate/processor.php</b> on line <b>145</b><br />
<b>Warning</b>: imagecopyresampled() expects parameter 2 to be resource, boolean given in /home/content/52/12096052/html/Testupdate/processor.php</b> on line <b>145</b><br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/content/52/12096052/html/Testupdate/processor.php:117) in <b>/home/content/52/12096052/html/Testupdate/processor.php</b> on line <b>186</b><br />
this is my code processor.php:
$con = mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname);
// make a note of the current working directory, relative to root.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
// make a note of the directory that will recieve the uploaded files //i made it as the same directory where the .php file is
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self;
// make a note of the location of the upload form in case we need it
$uploadForm = 'https://' . $_SERVER['HTTP_HOST'] . $directory_self . 'index.php';
// name of the fieldname used for the file in the HTML form
$fieldname = 'file';
// check the upload form was actually submitted else print form
if(isset($_POST['submit']))
{
if($_FILES['file']['tmp_name']!="")
{
$allowedExts = array("jpeg", "jpg");
$temp = explode(".", $_FILES['file']['name']);
$extension = end($temp);
$notallowedExts = array("png", "gif", "pdf", "doc", "docx", "txt", "html", "xlsx", "mov");
$nottemp = explode(".", $_FILES['file']['name']);
$notextension = end($nottemp);
if ((($_FILES['file']['type'] == "image/jpeg") || ($_FILES['file']['type'] == "image/jpg")) && ($_FILES['file']['size'] < 1300000) && in_array($extension, $allowedExts))
{
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{
$now++;
}
move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename);
}
elseif(($_FILES['file']['size'] > 1300000)||(in_array($notextension, $notallowedExts)))
{
echo '<script type="text/javascript">';
echo 'alert("Invalid file upload. Please check your input.");';
echo 'window.location.href = "index.php";';
echo '</script>';
die();
}
}
else
{
$uploadFilename = "def_img.jpg";
}
}
//for textbox input
$name = $_POST['name'];
$email = $_POST['email'];
$office_id = $_POST['office_id'];
$var_title = $_POST['title'];
$var_story = $_POST['story'];
$var_task = $_POST['task'];
$var_power = $_POST['power'];
$var_solve = $_POST['solve'];
$var_result = $_POST['result'];
$get_title = $_POST['title'];
$title = strtoupper ($get_title);
$namehere = "Super Story By " .$_POST['name'];
$story = "My super story begins with " . $_POST['story'] . " My task was " . $_POST['task'] ." With the super power of ". $_POST['power'] ." I solved it by ". $_POST['solve'] ." The result was ". $_POST['result'];
if (!empty($name) && !empty($email) && !empty($office_id) && !empty($title) && !empty($var_title) && !empty($var_story) && !empty($var_task) && !empty($var_power) && !empty($var_solve) && !empty($var_result)) {
header('Content-Type: image/jpeg');
$imagename = $uploadFilename;
$im = imagecreatefromjpeg("bg.jpg");
$img2 = imagecreatefromjpeg($imagename);
$black = imagecolorallocate($im, 0, 0, 0);
$font = 'arialbi.ttf';
$font2 = 'ariali.ttf';
$newtitle = wordwrap($title, 24, "\n", true);
$newertitle = explode("\n", $newtitle);
imagettftext($im, 33, 0, 8, 270, $black, $font, $newertitle[0]);
imagettftext($im, 33, 0, 8, 320, $black, $font, $newertitle[1]);
imagettftext($im, 12, 0, 283, 365, $black, $font, $namehere);
$newtext = wordwrap($story, 50, "\n", true);
$newertext = explode("\n", $newtext);
imagettftext($im, 10, 0, 283, 385, $black, $font2, $newertext[0]);
imagettftext($im, 10, 0, 283, 400, $black, $font2, $newertext[1]);
imagettftext($im, 10, 0, 283, 415, $black, $font2, $newertext[2]);
imagettftext($im, 10, 0, 283, 430, $black, $font2, $newertext[3]);
imagettftext($im, 10, 0, 283, 445, $black, $font2, $newertext[4]);
imagettftext($im, 10, 0, 283, 460, $black, $font2, $newertext[5]);
imagettftext($im, 10, 0, 283, 475, $black, $font2, $newertext[6]);
imagettftext($im, 10, 0, 283, 490, $black, $font2, $newertext[7]);
imagettftext($im, 10, 0, 283, 505, $black, $font2, $newertext[8]);
imagettftext($im, 10, 0, 283, 520, $black, $font2, $newertext[9]);
imagettftext($im, 10, 0, 283, 535, $black, $font2, $newertext[10]);
imagecopyresampled($im, $img2, 10, 350, 0, 0, 263, 175, imagesx($img2), imagesy($img2));
$date_created = date("YmdHis");//get date created
$img_name = "-img_entry.jpg"; //the file name of the generated image
$img_newname = $date_created . $img_name; //datecreated+name
$img_dir =dirname($_SERVER['SCRIPT_FILENAME']) ."/". $img_newname; //the location to save the image
imagejpeg($im, $img_dir , 80); //function to save the image with the name and quality
$newpath = "/home/content/52/12096052/html/Testupdate/image_entry/";
$newdir = $newpath.$img_newname;
copy ($img_dir, $newdir);
$http_dir = 'https://www.uaewebdeveloper.com/Testupdate/image_entry/';
$post_link = $http_dir . $img_newname;
$msg = 'Super Story by ';
$post_msg = $msg.$name;
imagedestroy($im);
}
else{
echo '<script type="text/javascript">';
echo 'window.alert("*All fields required.");';
echo 'window.location.href = "index.php";';
echo '</script>';
}
//get time to save in db
$sql_date = date("Y/m/d H:i:s");
//save inputs to db
if (!empty($name) && !empty($email) && !empty($office_id) && !empty($title) && !empty($story)) {
$save_sql = mysql_query("INSERT INTO `tbl_amatest` (filename, name, email, office_id, title, story, time) VALUES ('$img_newname','$name','$email','$office_id','$title','$story','$sql_date')");
header('Location:' .'success.html');
mysql_close($con);
}
when i specify the second image as the dafault, it works. but it's getting the only the default not the uploaded when someone uploads a file. so basically, i have two problems here:
the uploaded image is not being passed/uploaded properly
the default image is not being get from the server properly
please help me. i dont know what to do. i have read posts, almost the same but it didn't help me. thanks a lot in advance!

Try to do the major two change in your code :
Replace code if(isset($_FILES['file']['tmp_name'])){
With if($_FILES['file']['tmp_name']!=""){
Remove path from default image : $uploadFilename = 'def_img.jpg';
I have tried its working fine. The complete code by which i have test that default image and uploaded image both available for further processing.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
// make a note of the directory that will recieve the uploaded files //i made it as the same directory where the .php file is
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self;
#echo "$uploadsDirectory<br>";
#exit;
$fieldname = 'file';
if(isset($_POST['submit']))
{
if($_FILES['file']['tmp_name']!="")
{
$allowedExts = array("jpeg", "jpg");
$temp = explode(".", $_FILES['file']['name']);
$extension = end($temp);
$notallowedExts = array("png", "gif", "pdf", "doc", "docx", "txt", "html", "xlsx", "mov");
$nottemp = explode(".", $_FILES['file']['name']);
$notextension = end($nottemp);
if ((($_FILES['file']['type'] == "image/jpeg") || ($_FILES['file']['type'] == "image/jpg")) && ($_FILES['file']['size'] < 1300000) && in_array($extension, $allowedExts))
{
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{
$now++;
}
move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename);
}
elseif(($_FILES['file']['size'] > 1300000)||(in_array($notextension, $notallowedExts)))
{
echo '<script type="text/javascript">';
echo 'alert("Invalid file upload. Please check your input.");';
echo 'window.location.href = "index.php";';
echo '</script>';
die();
}
}
else
{
$uploadFilename = "images.jpg";
}
}
/*$get_title = $_POST['title'];
$story = "My super story begins with " . $_POST['story'] . " My task was " . $_POST['task'] ." With the super power of ". $_POST['power'] ." I solved it by ". $_POST['solve'] ." The result was ". $_POST['result'];
if (!empty($name) && !empty($email) && !empty($office_id) && !empty($title) && !empty($var_title) && !empty($var_story) && !empty($var_task) && !empty($var_power) && !empty($var_solve) && !empty($var_result)) {
*/
echo " FILE : $uploadFilename";
//header('Content-Type: image/jpeg');
$upload = $uploadFilename;
$im = imagecreatefromjpeg("bg.jpg");
$img2 = imagecreatefromjpeg($upload);
$black = imagecolorallocate($im, 0, 0, 0);
$font = 'arialbi.ttf';
$font2 = 'ariali.ttf';
$newtitle = wordwrap($title, 24, "\n", true);
$newertitle = explode("\n", $newtitle);
imagettftext($im, 33, 0, 8, 270, $black, $font, $newertitle[0]);
imagettftext($im, 33, 0, 8, 320, $black, $font, $newertitle[1]);
imagettftext($im, 12, 0, 283, 365, $black, $font, $namehere);
$newtext = wordwrap($story, 50, "\n", true);
$newertext = explode("\n", $newtext);
imagettftext($im, 10, 0, 283, 385, $black, $font2, $newertext[0]);
imagettftext($im, 10, 0, 283, 400, $black, $font2, $newertext[1]);
imagecopyresampled($im, $img2, 10, 350, 0, 0, 263, 175, imagesx($img2), imagesy($img2));
$date_created = date("YmdHis");//get date created
$img_name = "-img_entry.jpg"; //the file name of the generated image
$img_newname = $date_created . $img_name; //datecreated+name
$img_dir =dirname($_SERVER['SCRIPT_FILENAME']) ."/". $img_newname; //the location to save the image
imagejpeg($im, $img_dir , 80); //function to save the image with the name and quality
$newpath = "/home/content/52/12096052/html/Testupdate/image_entry/";
$newdir = $newpath.$img_newname;
copy ($img_dir, $newdir); //copy to new folder
$http_dir = 'https://www.uaewebdeveloper.com/Testupdate/image_entry/';
$post_link = $http_dir . $img_newname;
$msg = 'Super Story by ';
$post_msg = $msg.$name;
imagedestroy($im);
//}

Related

merge multiple images and text into single image but not able to arrange properly

How can I arrange a dynamic image?
its working fine but i need to put jd logo on upper left corner
and when i do that black color appears
code that i am using currently
createimageinstantly();
function createimageinstantly($img1='',$img2='',$img3=''){
$x=$y=1200;
header('Content-Type: image/png');
$targetFolder = 'D:/xampp/htdocs/festival/';
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$img1 = 'demo.jpg';
$img2 = 'img2.png';
$img3 = 'img3.png';
$outputImage = imagecreatetruecolor(1200, 1200);
// set background to white
$white = imagecolorallocate($outputImage, 0, 0, 0);
imagefill($outputImage, 0, 0, $white);
$first = imagecreatefromjpeg($img1);
$second = imagecreatefrompng($img2);
$third = imagecreatefrompng($img3);
imagecopyresized($outputImage,$first,0,0,0,0, $x, $y,$x,$y);
imagecopyresized($outputImage,$second,20,20,0,0, 1200, 1200, 1200,1200);
imagecopyresized($outputImage,$third,1140,1140,0,0, 130, 100, 204, 148);
// Add the text
$text = 'School Name Here';
$font = 'Calibribold.ttf';
imagettftext($outputImage, 32, 0, 150, 150, $white, $font, $text);
/*$filename =$targetPath .round(microtime(true)).'.png';
imagepng($outputImage, $filename);*/
imagejpeg($outputImage);
imagedestroy($outputImage);
}

Add text over an image when uploading it in PHP

I have a pictures website like Quickmeme.com and I would like to add text over images.
I currently let the user upload the picture manually, writing the comments with Paint program in Windows which is a bad idea and I need help ...
here is the code I use for Uploading an image, I am thinking of adding a text field below the upload field so what ever the user writes in that box will be printed on the image as an imagetext ... So how can I do that with php?
<?php if(isset($_POST["upload"])){
$tmp_name = $_FILES["file"]["tmp_name"];
$file_name = basename($_FILES["file"]["name"]);
$random = rand(1, 9999999999);
$directory = "Uploads/" . $random . $file_name;
$time = strftime("%H:%M:%S", time());
$date = strftime("%Y-%m-%d", time());
if(move_uploaded_file($tmp_name, $directory)){
if(mysql_query("")){
$query = mysql_query(""); $fetch = mysql_fetch_array($query);
if(mysql_query("")){
header("Location: index.php");
exit;
}
}
}
} ?>
Here is my website http://www.picturepunches.net
You can try
if (isset($_POST["upload"])) {
$tmp_name = $_FILES["file"]["tmp_name"];
$file_name = basename($_FILES["file"]["name"]);
$random = rand(1, 9999999999);
$directory = "Uploads/" . $random . $file_name;
$time = strftime("%H:%M:%S", time());
$date = strftime("%Y-%m-%d", time());
switch (strtolower(pathinfo($file_name, PATHINFO_EXTENSION))) {
case "jpg" :
$im = imagecreatefromjpeg($_FILES["file"]["tmp_name"]);
break;
case "gif" :
$im = imagecreatefromgif($_FILES["file"]["tmp_name"]);
break;
case "png" :
$im = imagecreatefrompng($_FILES["file"]["tmp_name"]);
break;
default :
trigger_error("Error Bad Extention");
exit();
break;
}
$font = 'verdana.ttf';
$grey = imagecolorallocate($im, 128, 128, 128);
$red = imagecolorallocate($im, 255, 0, 0);
// Add some shadow to the text
imagettftext($im, 10, 0, 11, 20, $grey, $font, $date);
imagettftext($im, 10, 0, 10, 35, $grey, $font, $time);
imagettftext($im, 10, 0, 10, 50, $red, $font, $random);
// imagepng($im);
imagedestroy($im);
if (move_uploaded_file($tmp_name, $directory)) {
if (mysql_query("")) {
$query = mysql_query("");
$fetch = mysql_fetch_array($query);
if (mysql_query("")) {
header("Location: index.php");
exit();
}
}
}
}
Output
Uploaded Final
First, check if you have the GD extension installed, next,
Use the GD functions
//Loading the file
$rImg = ImageCreateFromJPEG("MyPicture.jpg");
//Font Color (black in this case)
$color = imagecolorallocate($rImg, 0, 0, 0);
//x-coordinate of the upper left corner.
$xPos = 100;
//y-coordinate of the upper left corner.
$yPos = 30;
//Writting the picture
imagestring($rImg,5,$xPos,$yPos,"My text in the picture",$color);
//The new file with the text
header('Content-type: image/jpeg');
imagejpeg($rImg, NULL, 100);
you can use this tutorial
http://blog.doh.ms/2008/02/12/adding-text-to-images-in-real-time-with-php/

PHP GD: Image cannot be displayed because of errors

Okay.. so I've been trying to make a 'signature' for a game that I play.
The only catch is, I've been running into quite a few problems when wanting to insert an Avatar & Online/Offline image.
The two things I've been trying to do is:
Get user status from a webpage habplus.com/home/[username] by checking if habbo_offline.gif is present.
if(strpos(file_get_contents('http://www.habpl.us/home/'.$username.''),
'habbo_offline.gif') == true) {
Grab users image and display on the final image
function habSigFigure($username){
$omgfig = 'http://www.habpl.us/figure.php?user='.$username.'&img_format=gif';
return $omgfig;
//place habbo avatar
$habsigfig = imagecreatefromgif($omgfig);
imagecopy($img, $habsigfig, 13, 32, 0, 0, imagesx($habsigfig), imagesy($habsigfig));*/
//place habbo avatar
I've included the entire source code, and the and the page can be accessed here
-Another link with variables included
Hope you can help..
Sincerely yours, Malmoc
<?php
include 'config.php';
$username=$_REQUEST["user"];
$grabstat3 = fopen("http://habplus.com/fansitetools/userStats.php?user={$username}&stat=motto", "r");
while (!feof($grabstat3)){ $motto1 = fgets($grabstat3);
}
fclose($grabstat3);
$username=$_REQUEST["user"];
$grabstat2 = fopen("http://habplus.com/fansitetools/userStats.php?user={$username}&stat=pixels", "r");
while (!feof($grabstat2)){ $pixels1 = fgets($grabstat2);
}
fclose($grabstat2);
$username=$_REQUEST["user"];
$grabstat1 = fopen("http://habplus.com/fansitetools/userStats.php?user={$username}&stat=credits", "r");
while (!feof($grabstat1)){ $credits1 = fgets($grabstat1);
}
fclose($grabstat1);
$pixels = 'Pixels: '.$pixels1.'';
$credits = 'Credits: '.$credits1.'';
$motto = 'Motto: '.$motto1.'';
/* Get custom img */
if(empty($_REQUEST['img'])){
$img = 'default.png';
}else{
$img =$_REQUEST['img'];
}
/* TEXT COLORS */
$red =$_REQUEST['red'];
$green =$_REQUEST['green'];
$blue =$_REQUEST['blue'];
/* Font size */
$fsize =$_REQUEST['fsize'];
/*function habSigStatus($username){
if(strpos(file_get_contents('http://www.habpl.us/home/'.$username.''), 'habbo_offline.gif') == true){
return false;
}else{
return true;
function habSigFigure($username){
$omgfig = 'http://www.habpl.us/figure.php?user='.$username.'&img_format=gif';
return $omgfig;
}
}
}*/
/*
//place habbo avatar
$habsigfig = imagecreatefromgif($omgfig);
imagecopy($img, $habsigfig, 13, 32, 0, 0, imagesx($habsigfig), imagesy($habsigfig));*/
//place habbo avatar
//habbo status
if(strpos(file_get_contents('http://www.habpl.us/home/'.$username.''), 'habbo_offline.gif') == true){
$status_img = imagecreatefromgif('habbo_offline.gif');
}else{
$status_img = imagecreatefromgif('habbo_online.gif');
}
imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);
//habbo status
$image = imagecreatefrompng($img);
$font_color = imagecolorallocate($image, $red, $green, $blue);
imagefttext($image, $fsize, 0, 3, 12, $font_color, './volt.ttf', $credits); /* top left */
imagefttext($image, $fsize, 0, 403, 12, $font_color, './volt.ttf', $pixels); /* top right */
imagefttext($image, $fsize, 0, 3, 96, $font_color, './volt.ttf', $motto); /* bottom left */
imagefttext($image, $fsize, 0, 403, 96, $font_color, './volt.ttf', $online); /* bottom right */
/* imagefttext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text [, array $extrainfo]) */
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
$image should be a valid resource, in your code $image is null
$image = imagecreatefrompng($img);
imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);
you can use
$image = imagecreatetruecolor(50, 16); //width,height
imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);
Here's your problem, fairly derpy to be honest:
imagecopy($image, $status_img, 403, 96, 0, 0, 50, 16);
$image = imagecreatefrompng($img);
You kind of need to create the image before you can copy to it. Swap those two lines around and you should be good.

Captcha code validation not working

I have the following code validation php script:
if(empty($_POST['captcha_code'])) {
$error = 1;
$code[3] = 'color:#FF0000;';
} else {
include_once "formfiles/captcha.php";
$randomnr = new Securimage();
$valid = $randomnr->check($_POST['captcha_code']);
if(!$valid) {
$error = 1;
$code[3] = 'color:#FF0000;';
$code[4] = '<strong><span style="color:#FF0000;">Incorrect code</span></strong>';
}
}
and this captcha php code:
<?php
Securimage();
exit();
function Securimage()
{
$randomnr = rand(1000, 9999);
$_SESSION['randomnr2'] = md5($randomnr);
$im = imagecreatetruecolor(100, 38);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 150, 150, 150);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 200, 35, $black);
//path to font - this is just an example you can use any font you like:
$font = dirName(__FILE__).'/calvin.ttf';
imagettftext($im, 20, 4, 22, 30, $grey, $font, $randomnr);
imagettftext($im, 20, 4, 15, 32, $white, $font, $randomnr);
imagegif($im);
imagedestroy($im);
}
?>
After submitting my form I always get an awkward bit of code starting with gif. Where is my fault? Can somebody please help me?
You need to decalare header about the content type to browser recognize it as image. Try this
header('Content-Type: image/gif');
Securimage();
exit();

jQuery POST to GD image creation page

I have a jquery form that posts to a callback page. The callback page uses PHP's GD library to create an image.
The PHP code looks like this:
<?php
include 'inc/config.php';
$caseNum = $_POST['caseNum'];
$wish = $_POST['wish'];
$selectedWishes = join(", ", $wish);
$fname = $_POST['fname'];
$middlename = $_POST['middlei'];
$lname = $_POST['lname'];
$address1 = $_POST['adr1'];
$address2 = $_POST['adr2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$recipt = $_POST['recipt'];
$terms_accepted = $_POST['tou'];
if ($terms_accepted == 'accept') {
mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_database);
$select = mysql_query('SELECT * FROM children WHERE caseNumber="'.$caseNum.'" LIMIT 1 ');
$row = mysql_fetch_array($select);
header('Content-type: image/png');
$im = imagecreatefrompng ("images/card_bg.png");
$color = imagecolorallocate($im, 0, 0, 0);
$font = 'inc/fonts/MyriadPro-Regular.otf';
$size = 14;
imagettftext($im, $size, 0, 130, 18, $color, $font, $caseNum);
imagettftext($im, $size, 0, 52, 105, $color, $font, $row['age']);
imagettftext($im, $size, 0, 108, 167, $color, $font, $row['name']);
// Print wishes and word wrap
$lines = explode('|', wordwrap($selectedWishes, 30, '|'));
$y = 238;
foreach ($lines as $line) {
imagettftext($im, $size, 0, 18, $y, $color, $font, $line);
$y += 23;
}
imagettftext($im, $size, 0, 339, 151, $color, $font, $fname.' '.$middlename.' '.$lname);
imagettftext($im, $size, 0, 351, 175, $color, $font, $address1);
imagettftext($im, $size, 0, 365, 196, $color, $font, $address2);
imagettftext($im, $size, 0, 326, 218, $color, $font, $city);
imagettftext($im, $size, 0, 474, 218, $color, $font, $zip);
imagettftext($im, $size, 0, 340, 242, $color, $font, $phone);
imagettftext($im, 9, 0, 333, 268, $color, $font, $email);
if ($row['gender'] == 'male') {
$check = imagecreatefrompng('images/checkmark.png');
imagealphablending($check, true);
imagesavealpha($check, false);
imagecopymerge($im, $check, 74, 3, 0, 0, 10, 15, 80);
}
else if ($row['gender'] == 'female') {
$check = imagecreatefrompng('images/checkmark.png');
imagealphablending($check, true);
imagesavealpha($check, false);
imagecopymerge($im, $check, 74, 38, 0, 0, 10, 15, 80);
}
if ($recipt == 'yes') {
$check = imagecreatefrompng('images/checkmark.png');
imagealphablending($check, true);
imagesavealpha($check, false);
imagecopymerge($im, $check, 324, 383, 0, 0, 10, 15, 80);
}
else if ($recipt == 'no') {
$check = imagecreatefrompng('images/checkmark.png');
imagealphablending($check, true);
imagesavealpha($check, false);
imagecopymerge($im, $check, 367, 383, 0, 0, 10, 15, 80);
}
$imageName = rand();
$ourFileName = $imageName.'.png';
$ourFilePath = 'images/created_tags/';
imagepng ( $im, $ourFilePath.$ourFileName );
imagepng($im);
imagepng($check);
imagedestroy($check);
imagedestroy($im);
readfile ( $ourFileName );
print $ourFilePath.$ourFileName;
exit ();
}
?>
and here is the jQuery:
$.post('selectChildCallback.php', $("#select_child_form").serialize(), function(data) {
$("#post_image").append('<img src="'+ data.path +'" alt="card" />');
}, 'json');
What I can't figure out is how to make the callback page not display the image, but just the path. Right now it prints the image data instead of an image path.
readfile ( $ourFileName );
This line is the problem. According to the docs, it echos the contents of a file to the screen. So PHP is returning a image file (binary) with its file name concatenated to the end of the stream back to jQuery.
Remove this line, and this should work.
EDIT:
imagepng ( $im, $ourFilePath.$ourFileName );
imagepng($im);
imagepng($check);
Why do you call imagepng 3 times? If you don't give it a second parameter, it echos the image to the screen. Also remove the last 2 imagepng lines. PHP is actually returning 3 images concatenated together as well as the file name.
It should look like this:
$imageName = rand();
$ourFileName = $imageName.'.png';
$ourFilePath = 'images/created_tags/';
imagepng($im, $ourFilePath.$ourFileName);
imagedestroy($check);
imagedestroy($im);
echo $ourFilePath.$ourFileName;
exit();

Categories