PHP - Creating A String For Base64 From In Memory Image?
Hi group,
I need to create a string to be used by base64_encode to build an SVG file. The source for the string is an image I built in memory. Code: [Select] $img = imagecreatetruecolor( 50,50 ); Other stuff, draw circles, test, ect. I currently write it out to disk with: Code: [Select] imagepng( $img, "$Name.png" ); Then read it back in and process it to create an SVG file. I would like to avoid writing it to disk, so how can I create a string for base64_encode from an in memory image?? Thanks for your time. Similar TutorialsCode: [Select] echo '<img src="data:image/jpg/png/jpeg;base64,' . base64_encode( $row['image'] ) . '" height="150" />'; This is showing up images great in firefox, safari and chrome, but in internet explorer it shows a nice red cross, and I assume it is because of the encoding? Does anyone know how to get working in internet explorer as well? Pretty urgent job! Much appreciated for your help! An image is secured in the root directory, to be displayed to customer in html document.
This image can be displayed as a link to a php readfile page Which is better? Why and why not? Thank you. Edited yesterday at 01:15 PM by ChenXiuWhich is better? Why and why not? An image is secured in the root directory, to be displayed to customer in html document.
This image can be displayed as a link to a php readfile page Thank you.
I have a form on which the filepond plugin send the file manually
Look here if(empty($_POST['image'])) { echo 'add file!'; } $myimage = $_POST['image']; $myimage = str_replace('data:image/png;base64,', '', $myimage); $myimage = str_replace(' ', '+', $myimage); $decode = base64_decode($myimage); $myfile = $_SERVER['DOCUMENT_ROOT'].'/mages/' . uniqid() . '.png'; //now put the file file_put_contents($myfile, $decode);
Hi all I have a script that takes up to 3 images and resizes them. It works except for if you try and upload images over roughly 500kb. I then get the message: Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) Here's a snippet of the code for one image: Code: [Select] // Process image 1 : if(!empty($_FILES['image1']['name'])) { $imagelarge = $_FILES['image1']['tmp_name']; $imagelargemain = $_FILES['image1']['name']; $pathInfo = pathinfo($imagelargemain); $rand = rand(1, 100000000000000); $name = $rand . '.' . $pathInfo['extension']; $src = imagecreatefromjpeg($imagelarge); list($width,$height)=getimagesize($imagelarge); if ($width > $height) { $newwidth=600; $newheight=($height/$width)*$newwidth; } elseif ($height > $width) { $newheight=400; $newwidth=($width/$height)*$newheight; } $center_x = (600/2)-($newwidth/2); $center_y = (400/2)-($newheight/2); $tmp=imagecreatetruecolor(600,400); $white = imagecolorallocate($tmp, 255, 255, 255); imagefill($tmp, 0, 0, $white); imagecopyresampled($tmp,$src,$center_x,$center_y,0,0,$newwidth,$newheight,$width,$height); $filename = WEB_UPLOAD."images/adverts/". $name; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); $image_sql = mysql_query("UPDATE `adverts` SET image1 ='".$name."' WHERE id='".$insertid."'") or die ("Error updating database"); } Any ideas why this happens? Many thanks Pete Hi I have an upload script which uploads an image then resizes The error Code: [Select] Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 7776 bytes) in Dir/UploadScript.php on line 234 The code function $strNewFileName = date("YmdHis").rand(0,5000).".".$this->strFileExt; $this->strNewFileName = $strNewFileName; $strDir = $_SERVER['DOCUMENT_ROOT'].$this->strSaveDir.$strNewFileName; $strTNDir = $_SERVER['DOCUMENT_ROOT'].$this->strSaveDir."tn_".$strNewFileName; move_uploaded_file($this->arrUploadFile['tmp_name'], $strDir); $image_p = imagecreatetruecolor($this->intNewWidth, $this->intNewHeight); switch($this->strFileExt){ case "jpg": $image = imagecreatefromjpeg($strDir); break; case "gif": $image = imagecreatefromgif($strDir); break; case "png": $image = imagecreatefrompng($strDir); break; } imagecopyresampled($image_p, $image, 0, 0, 0, 0, $this->intNewWidth, $this->intNewHeight, $this->intCurWidth, $this->intCurHeight); $blnSuccessUpload = false; switch($this->strFileExt){ case "jpg": if(imagejpeg($image_p, $strTNDir)){ $blnSuccessUpload = true; } break; case "gif": if(imagegif($image_p, $strTNDir)){ $blnSuccessUpload = true; } break; case "png": if(imagepng($image_p, $strTNDir)){ $blnSuccessUpload = true; } } imagedestroy($image_p); return $blnSuccessUpload; the Line causing issues (234) is Code: [Select] $image = imagecreatefromjpeg($strDir); Now that image is created but the TN is not //Edit Just a note. I have ini_set('memory_limit', 16MB); if you notice the allocated memory is less than the memory allowed. Can anyone help me with the following please. Upon loading the page, I want to generate a random string based of the following... Select one value from the following array Code: [Select] $categories = array("easy", "medium", "hard")And generate a random number from one to five. The string would then look like hard1 or easy5 etc.. Then check if the string generated exists in the following session array Code: [Select] $_SESSION['asked']If not, add it to that array and continue, if it is, create a new random string and check if that one exists and loop until its found one that isn't. Thank you in advance I have a string (Product1-Product2-Product3#2-4-1) where Product1-Product2-Product3 are products and 2-4-1 are quantities. I am struggling to make a table out of it where products and quantities are shown in rows. here is what i tried. Code: [Select] list($products, $quantities) = explode("#", $specs); //to separate Quantities from products <?php foreach(preg_split("/-/", $products) as $product_list) { ?> <tr> <td> <?php echo $product_list; ?></td><? } ?> <?php foreach(preg_split("/-/", $quantities) as $qtylist) { ?> <td></td> <td><?php echo $qtylist; ?></td> <?php } ?> </tr> <?php //} ?> </table> I know something is wrong with this and its giving me unexpected reasult Please help me create a table out of the above string. Many Thanks -Max I have implemented the base64_encode() function with some custom mapping table so I could encode some binary data more securely without anyone knowing how to decode it here is the class <?php class Base64 { /** * I have changed letter placement (P <=> x, S <=> 9) and the cases * You can completely redo the mapping table */ private static $BinaryMap = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', // 7 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'x', // 15 'q', 'r', '9', 't', 'u', 'v', 'w', 'x', // 23 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', // 31 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', // 39 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', // 47 'W', 'P', 'Y', 'Z', '0', '1', '2', '3', // 55 '4', '5', '6', '7', '8', 'S', '+', '/', // 63 '=', // padding char ); public function __construct() {} public function base64_encode($input) { $output = ""; $chr1 = $chr2 = $chr3 = $enc1 = $enc2 = $enc3 = $enc4 = null; $i = 0; // $input = self::utf8_encode($input); while($i < strlen($input)) { $chr1 = ord($input[$i++]); $chr2 = ord($input[$i++]); $chr3 = ord($input[$i++]); $enc1 = $chr1 >> 2; $enc2 = (($chr1 & 3) << 4) | ($chr2 >> 4); $enc3 = (($chr2 & 15) << 2) | ($chr3 >> 6); $enc4 = $chr3 & 63; if (is_nan($chr2)) { $enc3 = $enc4 = 64; } else if (is_nan($chr3)) { $enc4 = 64; } $output .= self::$BinaryMap[$enc1] . self::$BinaryMap[$enc2] . self::$BinaryMap[$enc3] . self::$BinaryMap[$enc4]; } return $output; } public function utf8_encode($input) { $utftext = null; for ($n = 0; $n < strlen($input); $n++) { $c = ord($input[$n]); if ($c < 128) { $utftext .= chr($c); } else if (($c > 128) && ($c < 2048)) { $utftext .= chr(($c >> 6) | 192); $utftext .= chr(($c & 63) | 128); } else { $utftext .= chr(($c >> 12) | 224); $utftext .= chr((($c & 6) & 63) | 128); $utftext .= chr(($c & 63) | 128); } } return $utftext; } } ?> and the usage as follows: <?php $string = pack('H*', "31c85c5aaa56c1f0102301ea497d0ab010e4e131af261787"); //HEX echo Base64::base64_encode($string); echo "<br />"; echo base64_encode($string); ?> and the output will be: mCHCwQPwWFaqiWhQ9x0kSbdK4tgVjHEh // with custom mapping MchcWqpWwfAQIwHqSX0KsBDk4TGvJheH // the base64_encode() I need help how to decode the this key Hi, Im trying to use base64_decode on a string, however the string is sometimes plain text others its encoded, how can i test to see if the sting is encoded or plaintext and only perform the decode if the string is indeed encoded? Im pretty new to PHP, but ive seen mentions of regex or preg_match for certain characteristics of base64 encoded, my one observation is it usually ends in == which wouldnt appear in my plain text, could i do a preg match for that? url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAAoCAYAAAA16j4lAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkF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FHl+R0cuWiQJoBl0AXEl6FQUY6z8FMxD1kmICjDF1UKUxMILKTJbIcIWh2pNKgJosmiesJcEvDJ2f6nCdYOaJ2BNXM+Rbk8Wv4JzN2ee8h5vJ4F3WUDHW4ybDPnrWUFVVVTUwbOFYmgpZRyWZp9L0KtkAHAvX49hsz5osPhvzycpCBYZWDI0AWqhIepf2vYFxPdds/zZYpHqtPtZkYY06NFQb5tK+c+fO/L/2NgkL4uckEVmmwoOqhDVUiGFzzrCIklVTUxNmlsvOnQSUtIQarCg9YX5ScFLKymTxXptdNMGAGjY7BykeBjJDIPon0nm1lSV71mTF43F+Y5xlYRm1EDUmaThLd2QMTdoUAqY+IckxSLQBDdfY2tpa+ZosLN7AJkTsgbksDqNP5ZQiWWHozP6IjTTEeUXpsS1cuNBVPX799ddZvpLj89x8ELYFCxbYwxeW7BSw2dq0adPS/ADcmZTgXCi5Iiw0YeZae3p6MmQOF/PCrNgRSqYsvfH7FFWW6nAcmZuMDVMWhobLgdbQmixMoOSaLN7jcATaIWF1dumR1YR8uLOCROSPh4UZwoFoF+cVpefXXnzxxcYTJ06cgmSkIQVqABvMXDI1RIGvU5mswNw43yE1WbDTnfyE59q1a/nLly+bvIe+hMtLhUh1dfVg4WBQLGTqk/tCaSdTsFjxbsmOR/vqq6/4TVUWXvuI1mTt3bs3yW+X7WFnOY3/TcSZM2fu1mTd6e1/AgwAINwEgYdXHAgAAAAASUVORK5CYII=")How do I go about decoding this, it contains a number of different images I have just installed a new theme for my site at JamesGeddes.com however I want to edit the php footer file This, however, is coded in base64; fine for browsers, not so great for people! The file is at http://jamesgeddes.com/wp-content/themes/techno/footer.php but so that you can look at it I have copied the contents to a text file http://jamesgeddes.com/wp-content/themes/techno/txt/footer.txt How can I turn this base64 nonsense in to normal PHP code? Thanks for your help! James Hi guys, I'm parsing a bunch of html sources, some of them (a minority) contain base64 encoded URLs. At least 20-30 URLs per page. Some of the information I need is taken from the URLs. I'm looking for a way to parse these URLs without losing too much time (20-30 URLs per page and I need to parse about 10k pages daily). Should I regex each source individually for base64 encoded URLs and then decode them each time and isn't that going to take a lot of time/resources (especially considering it's only a minority that have the base64 URLs in them)? Or is there a better way to do it? Code snippets are absolutely welcome! Thank you in advance I want to add some text onto an image. Sometimes I either get nothing returned or I get a shit load of garbage returned. Garbage in the form of little question mark symbols and other crap like that. PHP File - show Tickets Code: [Select] include("createImage.php"); while( $row = mysql_fetch_array( $r ) ){ echo generateTicket( $row['ticketNumber'] ) . "<br /><br />"; } PHP - createImage.php Code: [Select] <? header("Content-type: image/jpeg"); function generateTicket( $ticketNum ){ $imageFile = "images/ticket.jpeg"; if( file_exists( $imageFile ) ){ $im = @imagecreatefromjpg( $imageFile ); $text_color = imagecolorallocate( $im, 0, 0, 0 ); imagestring( $im, 6, 25, 150, $ticketNum, $text_color ); imagejpeg( $im ); }else echo 'error'; } ?> Hi, I need help in my code. I have written a CAPTCHA code, but it is not appearing when I test run in my website. My code is below, could anyone highlight to me my error? Any problems to those that were highlighted in red? Thanks <?php session_start(); // Set some important CAPTCHA constants define('CAPTCHA_NUMCHARS', 6); // number of characters in pass-phrase define('CAPTCHA_WIDTH', 100); // width of image define('CAPTCHA_HEIGHT', 25); // height of image // Generate the random pass-phrase $pass_phrase = ""; for ($i = 0; $i < CAPTCHA_NUMCHARS; $i++) { $pass_phrase .= chr(rand(97, 122)); //chr(), convert a number to its ASCII character equivalent } // Store the encrypted pass-phrase in a session variable $_SESSION['pass_phrase'] = SHA($pass_phrase); // Create the image $img = imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT); // Set a white background with black text and gray graphics $bg_color = imagecolorallocate($img, 255, 255, 255); // white $text_color = imagecolorallocate($img, 0, 0, 0); // black $graphic_color = imagecolorallocate($img, 64, 64, 64); // dark gray // Fill the background imagefilledrectangle($img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bg_color); // Draw some random lines for ($i = 0; $i < 5; $i++) { imageline($img, 0, rand() % CAPTCHA_HEIGHT, CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color); } // Sprinkle in some random dots for ($i = 0; $i < 50; $i++) { imagesetpixel($img, rand() % CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color); } // Draw the pass-phrase string imagettftext($img, 18, 0, 5, CAPTCHA_HEIGHT - 5, $text_color, 'Courier New Bold.ttf', $pass_phrase); // Output the image as a PNG using a header header("Content-type: image/png"); imagepng($img); // Clean up imagedestroy($img); ?> Hello,
I have a website called http://flappycreator.com/ where users can upload multiple images to create their own version of Flappy Bird. As a result of this I created a PHP page that takes a GET param to create a preview image of their game to display in various locations on the website.
Here is an example:
http://flappycreator...d=5305a9ad9dc30
http://flappycreator...d=5305a9ad9dc30
http://flappycreator...d=5305a9ad9dc30
My issue is, I have given my users the ability to upload PNGs or JPGs and trying to figure out reliable code to display the preview has become a huge hassle. In the example above the Pac-Man character shows a white background but when you play the game, it is actually transparent. In other situations I am getting extremely bad color distortion. The code I have provided is my final attempt after a ton of trial-and-error and the PNG imagealphablending() and imagesavealpha() commands have shown me the best results, however I don't know what they do.
Please help! Thanks.
<?php $bird_picture = "default/bird.png"; $tube1_picture = "default/tube1.png"; $tube2_picture = "default/tube2.png"; $ground_picture = "default/ground.png"; $bg_picture = "default/bg.png"; // If an id is set, then reset values if (isset ( $_GET ['id'] )) { require ('XXX.php'); $db = new DBAccess (); $query = "SELECT * FROM XXX WHERE XXX = '{$_GET['id']}'"; $result = $db->query ( $query ); $num_results = $result->num_rows; $row = mysqli_fetch_array ( $result ); if ($num_results != 0) { if ($row ['bird_picture'] != "") { $bird_picture = "instances/" . $row ['folder_dir'] . "/" . $row ['bird_picture']; } if ($row ['tube1_picture'] != "") { $tube1_picture = "instances/" .$row ['folder_dir'] . "/" . $row ['tube1_picture']; } if ($row ['tube2_picture'] != "") { $tube2_picture = "instances/" .$row ['folder_dir'] . "/" . $row ['tube2_picture']; } if ($row ['ground_picture'] != "") { $ground_picture = "instances/" . $row ['folder_dir'] . "/" . $row ['ground_picture']; } if ($row ['bg_picture'] != "") { $bg_picture = "instances/" . $row ['folder_dir'] . "/" . $row ['bg_picture']; } } } $temp = explode(".", $bg_picture); $extension = end($temp); if ($extension == "jpeg" || $extension == "jpg") { $background = imagecreatefromjpeg($bg_picture); } else { $background = imagecreatefrompng($bg_picture); // Turn off alpha blending and set alpha flag imagealphablending($background, true); imagesavealpha($background, true); } $temp = explode(".", $ground_picture); $extension = end($temp); if ($extension == "jpeg" || $extension == "jpg") { $ground = imagecreatefromjpeg($ground_picture); } else { $ground = imagecreatefrompng($ground_picture); // Turn off alpha blending and set alpha flag imagealphablending($ground, false); imagesavealpha($ground, true); } $temp = explode(".", $bird_picture); $extension = end($temp); if ($extension == "jpeg" || $extension == "jpg") { $bird = imagecreatefromjpeg($bird_picture); } else { $bird = imagecreatefrompng($bird_picture); // Turn off alpha blending and set alpha flag imagealphablending($bird, false); imagesavealpha($bird, true); } $temp = explode(".", $tube1_picture); $extension = end($temp); if ($extension == "jpeg" || $extension == "jpg") { $tube1 = imagecreatefromjpeg($tube1_picture); } else { $tube1 = imagecreatefrompng($tube1_picture); // Turn off alpha blending and set alpha flag imagealphablending($tube1, false); imagesavealpha($tube1, true); } $temp = explode(".", $tube2_picture); $extension = end($temp); if ($extension == "jpeg" || $extension == "jpg") { $tube2 = imagecreatefromjpeg($tube2_picture); } else { $tube2 = imagecreatefrompng($tube2_picture); // Turn off alpha blending and set alpha flag imagealphablending($tube2, false); imagesavealpha($tube2, true); } imagecopymerge($background, $tube1, 200, -200, 0, 0, 52, 320, 100); imagecopymerge($background, $tube2, 200, 200, 0, 0, 52, 320, 100); imagecopymerge($background, $ground, 0, 320, 0, 0, 336, 112, 100); imagecopymerge($background, $bird, 70, 190, 0, 0, 36, 26, 100); header('Content-Type: image/png'); imagepng($background); # Destroy imagedestroy($background); imagedestroy($ground); imagedestroy($bird); imagedestroy($tube1); imagedestroy($tube2); ?>Attached Files preview.php 3.31KB 1 downloads Hey all, I'm trying to upload multiple image(which works great) but the problem I'm having is when an image is uploaded it over-rights a previous image if they are the same name and the old one is gone. Solution: create a unique name for each image before it's uploaded, change the name and then upload it. I can't seem to figure the correct syntax. My thought was to take the image name and add a random number to the front of it. Am i going about this the right way? thanks for the replies in advance. code below Code: [Select] if (isset($_POST['Submit'])) { $number_of_file_fields = 0; $number_of_uploaded_files = 0; $number_of_moved_files = 0; //creating my random number $random_digit=rand(0000,9999); $uploaded_files = array(); $upload_directory = dirname(__file__) . '/car-images/'; //set upload directory for ($i = 0; $i < count($_FILES['images']['name']); $i++) { $number_of_file_fields++; if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not $number_of_uploaded_files++; $uploaded_files[] = $_FILES['images']['name'][$i]; if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) { $number_of_moved_files++; } } } $image0 = $uploaded_files[0]; $image1 = $uploaded_files[1]; $image2 = $uploaded_files[2]; $image3 = $uploaded_files[3]; $image4 = $uploaded_files[4]; Been just trying to test out some basic code that utilizes gd. In Chrome i receive a blank page. In firefox I get "The image "image.php" cannot be displayed because it contains errors". There is no whitespace before or after the php tags, which seems to cause this error sometimes. $image = imagecreate(200,20); $background = imagecolorallocate($image, 0, 0, 0); $foreground = imagecolorallocate($image,255,255,255); imagestring($image, 5, 5, 1, "Test", $foreground); header("Content-type: image/jpeg"); $imagejpeg($image); I am just following a tutorial, and at this point in the tutorial i should get at least some garbled text, if not an image. I looked at other common causes. gd2 is un-commented in php.ini. phpinfo shows: GD Support enabled GD Version bundled (2.0.34 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.4.3 GIF Read Support enabled GIF Create Support enabled JPEG Support enabled libJPEG Version 6b PNG Support enabled libPNG Version 1.2.46 WBMP Support enabled XBM Support enabled gd.jpeg_ignore_warning 0 0 I have not found any other solutions to try, or maybe I have made an error is checking these solutions. Any advice with be great! Thank you for your time. Hi there I've been working with some code to display a single record on page. This all works fine and I'm able to pull what I want from the database. My problems is trying to use that data and turning it into something else like a link. I have a field in the database called image url which contains rows of image urls. So here is the problem area of the code: Code: [Select] <?php //////Displaying Data///////////// $id=$_GET['id']; // Collecting data from query string if(!is_numeric($id)){ // Checking data it is a number or not echo "Data Error"; exit; } $fetch=mysql_query("select * from productfeeds where ProductID=$id "); $row=mysql_fetch_object($fetch); echo mysql_error(); echo "<table>"; echo " <tr><td><b>ProductID</b></td><td>$row->ProductID</td></tr> <tr><td><b>ProductName</b></td><td>$row->ProductName</td></tr> <tr><td><b>ProductPrice</b></td><td>$row->ProductPrice</td></tr> //problem area for me <tr><td><b>Image</b></td><td>$row->ImageURL</td></tr> echo "</table>"; I'm trying to edit this part of the code: <tr><td><b>Image</b></td><td>$row->ImageURL</td></tr> I've tried this: <tr><td><b>Image</b></td><td><a href='{$row['URL']}'> <img src='{$row['ImageURL']}'></a> and <tr><td><b>Image</b></td><td><a href='$row['URL']'> <img src='$row['ImageURL']'></a> //removed brackets but I'm just getting errors. Can you guys help please? Thank you very much. Hello Forums, So basically I am trying to place text over an image. It works but the max text size is 5 which is way too small for my needs! What can I do to increase the size of the text? If anyone can help it would be much appreciated. Here is my code: Code: [Select] <?php $title = $_REQUEST['title'] ; $my_img = imagecreatefrompng ( "Template.png" ); $text_color = imagecolorallocate( $my_img, 0, 0, 0 ); imagestring( $my_img, 5, 30, 25, "$title", $text_colour ); header( "Content-type: image/png" ); imagepng( $my_img ); imagecolordeallocate( $text_color ); imagedestroy( $my_img ); ?> |