dsbpac Posted December 26, 2012 Share Posted December 26, 2012 I have a script that works perfect in designing custom items like business cards. I can't figure out how to add a button at the bottom to where it saves the image to the server when someone clicks save image. Any help would be greatly appriciated! HTMl CODE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link href="css/styles.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="scripts/client-side.js"></script> </head> <body> <h3>Business Card Preview</h3> <div class="preview"> <img src="scripts/server-side.php" /> </div> <form id="realtime-form" action="#" method="post"> <fieldset> <legend>Business Card Builder Form</legend> <ol> <li class="left"> <fieldset> <legend class="accessibility">Company Information</legend> <ol> <li> <label for="company-name">Company name:</label> <input type="text" id="company-name" name="companyName" value="Company Name" /> </li> <li> <label for="company-slogan">Company slogan:</label> <input type="text" id="company-slogan" name="companySlogan" value="Company Slogan" /> </li> <li> <label for="business-address">Business address</label> <textarea id="business-address" name="businessAddress">1234 Main Street Suite 101 City, ST 12345</textarea> </li> </ol> </fieldset> </li> <li class="right"> <fieldset> <legend class="accessibility">Contact Information and Description</legend> <ol> <li> <label for="full-name">Full name:</label> <input type="text" id="full-name" name="fullName" value="John Smith" /> </li> <li> <label for="job-title">Job title</label> <input type="text" id="job-title" name="jobTitle" value="Job Title" /> </li> <li> <label for="primary-phone">Primary phone</label> <input type="text" id="primary-phone" name="phoneOne" value="P: 954-555-1234" /> </li> <li> <label for="secondary-phone">Secondary phone</label> <input type="text" id="secondary-phone" name="phoneTwo" value="P: 954-555-5678" /> </li> <li> <label for="email-address">Email address</label> <input type="text" id="email-address" name="emailAddress" value="[email protected]" /> </li> <li> <label for="web-address">Web address</label> <input type="text" id="web-address" name="siteUrl" value="websiteurl.com" /> </li> </ol> </fieldset> </li> </ol> </fieldset> </form> </body> </html> PHP CODE <?php header ("Content-type: image/png"); $companyName = $_GET["companyName"]; $companySlogan = $_GET["companySlogan"]; $fullName = $_GET["fullName"]; $jobTitle = $_GET["jobTitle"]; $businessAddress = $_GET["businessAddress"]; $businessAddress = str_replace("\\n","\n",$businessAddress); $businessAddress = str_replace("\\","",$businessAddress); $phoneOne = $_GET["phoneOne"]; $phoneTwo = $_GET["phoneTwo"]; $emailAddress = $_GET["emailAddress"]; $siteUrl = $_GET["siteUrl"]; $handle = imagecreatefrompng( 'template.png' ); $brown = ImageColorAllocate ($handle, 84, 48, 26); $lightBrown = ImageColorAllocate ($handle, 145, 116, 94); $white = ImageColorAllocate ($handle, 255, 255, 255); $peach = ImageColorAllocate ($handle, 238, 222, 200); //company name ImageTTFText ($handle, 18, 0, 20, 35, $brown, "timesbd.ttf", $companyName); //company slogan ImageTTFText ($handle, 9, 0, 20, 50, $lightBrown, "GOTHIC.TTF", $companySlogan); //full name ImageTTFText ($handle, 14, 0, 20, 110, $white, "times.ttf", $fullName); //job title ImageTTFText ($handle, 9, 0, 19, 122, $peach, "GOTHIC.TTF", $jobTitle); //business address ImageTTFText ($handle, 10, 0, 20, 160, $brown, "GOTHIC.TTF", $businessAddress); //phone number #1 ImageTTFText ($handle, 9, 0, 317, 160, $brown, "GOTHIC.TTF", $phoneOne); //phone number #2 ImageTTFText ($handle, 9, 0, 317, 175, $brown, "GOTHIC.TTF", $phoneTwo); //email address ImageTTFText ($handle, 9, 0, 275, 190, $brown, "GOTHIC.TTF", $emailAddress); //site url (exmple of how to center copy) $fontSize = "12"; $width = "420"; $textWidth = $fontSize * strlen($siteUrl); $position_center = $width / 2 - $textWidth / 2.6; ImageTTFText ($handle, $fontSize, 0, $position_center, 240, $brown, "GOTHICB.TTF", $siteUrl); imagealphablending( $handle, false ); imagesavealpha( $handle, true ); ImagePng ($handle); imagedestroy( $handle ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/272385-phpgd-image-save/ Share on other sites More sharing options...
dpiearcy Posted December 27, 2012 Share Posted December 27, 2012 (edited) Not sure what you're asking here. Help with the PHP or actually inserting the grab a picture field? The html would be: <input name="uploaded_file" type="file"/> Of course that name can be anything as long as you remember it in the php side of things to get that file. For the php side I do a number of things to upload images to the server. I manage the size etc. Let me know if you're wanting a copy of that. Edited December 27, 2012 by dpiearcy Quote Link to comment https://forums.phpfreaks.com/topic/272385-phpgd-image-save/#findComment-1401455 Share on other sites More sharing options...
dsbpac Posted December 27, 2012 Author Share Posted December 27, 2012 Yeah I would like a copy of that as well. TYVM! Quote Link to comment https://forums.phpfreaks.com/topic/272385-phpgd-image-save/#findComment-1401561 Share on other sites More sharing options...
dsbpac Posted December 27, 2012 Author Share Posted December 27, 2012 I was able to get the item too save like I wanted using the imagejpeg($handle, 'simpletext.jpg'); Everything is working fine in my script just have one issue that IDK how to do. The image that I'm displaying I want to keep it at 100% quality so I don't want to resize the picture. How can I resize the picture to a % of what it really is and output it at 100% still? This is my code <?php header ("Content-type: image/png"); $companyName = $_GET["companyName"]; $companySlogan = $_GET["companySlogan"]; $fullName = $_GET["fullName"]; $jobTitle = $_GET["jobTitle"]; $businessAddress = $_GET["businessAddress"]; $businessAddress = str_replace("\\n","\n",$businessAddress); $businessAddress = str_replace("\\","",$businessAddress); $phoneOne = $_GET["phoneOne"]; $phoneTwo = $_GET["phoneTwo"]; $emailAddress = $_GET["emailAddress"]; $siteUrl = $_GET["siteUrl"]; $handle = imagecreatefrompng( 'template.png' ); $brown = ImageColorAllocate ($handle, 84, 48, 26); $lightBrown = ImageColorAllocate ($handle, 145, 116, 94); $white = ImageColorAllocate ($handle, 255, 255, 255); $peach = ImageColorAllocate ($handle, 238, 222, 200); //company name ImageTTFText ($handle, 18, 0, 20, 35, $brown, "timesbd.ttf", $companyName); //company slogan ImageTTFText ($handle, 9, 0, 20, 50, $lightBrown, "GOTHIC.TTF", $companySlogan); //full name ImageTTFText ($handle, 14, 0, 20, 110, $white, "times.ttf", $fullName); //job title ImageTTFText ($handle, 9, 0, 19, 122, $peach, "GOTHIC.TTF", $jobTitle); //business address ImageTTFText ($handle, 10, 0, 20, 160, $brown, "GOTHIC.TTF", $businessAddress); //phone number #1 ImageTTFText ($handle, 9, 0, 317, 160, $brown, "GOTHIC.TTF", $phoneOne); //phone number #2 ImageTTFText ($handle, 9, 0, 317, 175, $brown, "GOTHIC.TTF", $phoneTwo); //email address ImageTTFText ($handle, 9, 0, 275, 190, $brown, "GOTHIC.TTF", $emailAddress); //site url (exmple of how to center copy) $fontSize = "12"; $width = "420"; $textWidth = $fontSize * strlen($siteUrl); $position_center = $width / 2 - $textWidth / 2.6; ImageTTFText ($handle, $fontSize, 0, $position_center, 240, $brown, "GOTHICB.TTF", $siteUrl); imagealphablending( $handle, false ); imagesavealpha( $handle, true ); ImagePng ($handle); imagejpeg($handle, 'simpletext.jpg'); imagedestroy( $handle ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/272385-phpgd-image-save/#findComment-1401577 Share on other sites More sharing options...
lemmin Posted December 27, 2012 Share Posted December 27, 2012 Are you saying you want to make a smaller "thumbnail" size of the image and link it to the original? What you are asking for literally is impossible. Quote Link to comment https://forums.phpfreaks.com/topic/272385-phpgd-image-save/#findComment-1401579 Share on other sites More sharing options...
dsbpac Posted December 27, 2012 Author Share Posted December 27, 2012 Okay I will do some research and figure out another way to approach it ty Quote Link to comment https://forums.phpfreaks.com/topic/272385-phpgd-image-save/#findComment-1401583 Share on other sites More sharing options...
dpiearcy Posted December 27, 2012 Share Posted December 27, 2012 What I do is upload the original then make a copy of that original and add "resized" before the name of it. So it's still called the same thing but now the smaller version has "resized_imgname.jpg" and so forth. Here is the script I use. Got this from another source (not sure if I'm allowed to say who or where so I'll pass). <?php // Access the $_FILES global variable for this specific file being uploaded // and create local PHP variables from the $_FILES array of information $fileName = $_FILES["uploaded_file"]["name"]; // The file name $fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_FILES["uploaded_file"]["type"]; // The type of file it is $fileSize = $_FILES["uploaded_file"]["size"]; // File size in bytes $fileErrorMsg = $_FILES["uploaded_file"]["error"]; // 0 for false... and 1 for true $kaboom = explode(".", $fileName); // Split file name into an array using the dot $fileExt = end($kaboom); // Now target the last array element to get the file extension // START PHP Image Upload Error Handling -------------------------------------------------- if (!$fileTmpLoc) { // if file not chosen echo "ERROR: Please browse for a file before clicking the upload button."; exit(); } else if($fileSize > 5242880) { // if file size is larger than 5 Megabytes echo "ERROR: Your file was larger than 5 Megabytes in size."; unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder exit(); } else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) { // This condition is only if you wish to allow uploading of specific file types echo "ERROR: Your image was not .gif, .jpg, or .png."; unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder exit(); } else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1 echo "ERROR: An error occured while processing the file. Try again."; exit(); } // END PHP Image Upload Error Handling ---------------------------------------------------- // Place it into your "uploads" folder mow using the move_uploaded_file() function $moveResult = move_uploaded_file($fileTmpLoc, "uploads/$fileName"); // Check to make sure the move result is true before continuing if ($moveResult != true) { echo "ERROR: File not uploaded. Try again."; unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder exit(); } unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder function ak_img_resize($target, $newcopy, $w, $h, $ext) { list($w_orig, $h_orig) = getimagesize($target); $scale_ratio = $w_orig / $h_orig; if (($w / $h) > $scale_ratio) { $w = $h * $scale_ratio; } else { $h = $w / $scale_ratio; } $img = ""; $ext = strtolower($ext); if ($ext == "gif"){ $img = imagecreatefromgif($target); } else if($ext =="png"){ $img = imagecreatefrompng($target); } else { $img = imagecreatefromjpeg($target); } $tci = imagecreatetruecolor($w, $h); // imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h) imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig); imagejpeg($tci, $newcopy, 80); } $target_file = "uploads/$fileName"; $resized_file = "uploads/resized_$fileName"; //rename the file adding resized_in front of the original name so you have both $wmax = 200; //choose the maximum width of the image $hmax = 150; //choose the maximum height of the image ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt); This works very well as is. Just change the size you want the image size to be stored at. I then create a variable to store in MySql of the image name (in my uploads folder) then just echo out the location of that image. (obviously you know the image name since it has a variable already of $resized_file just add the path to it and store that variable in MySql). Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/272385-phpgd-image-save/#findComment-1401590 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.