PHP - Make Image Smaller So It Looks Good
Hi!
I using PHP - GD to rotate an image and put a watermark to it, that works great! But I want to make the image smaller because the image the user uploads is big. I can make the image smaller by: style="width: 300px; height:300px;" but the quality is not good then. My question is how I can make the image smaller, with GD if that's necessary. I guess I want to keep the proportion so I got a normal picture and not to width or to height or something. I want the picture width a width like 300-320 px how do i know how much the height will be? And do i need to crop the image? And how do I crop the image and still beeing sure to keep the face of the person on the picture? The width and height need to be same at all images! Thanks in advance, I really hope you can help me with this, this is really important! =) Similar Tutorialshello, if i have $big=3410 how can i take the last 2 digits of that to make it so that i only get the 10? hope this makes sence. Code: [Select] <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $width=120; $height=60; $image= imagecreate($width, $height); $txt=substr(md5(rand()),0,8); $white= imagecolorallocate($image, 255, 255, 255); $black= imagecolorallocate($image, 0, 0, 0); $red= imagecolorallocate($image, 255, 0, 0); $new= imagecolorallocate($image, 128, 128, 255); //imagefilledrectangle($image, 10, 10, 110, 50, $white); imagefilledrectangle($image, 20, 20, $width-20, $height-20, $new); imagestring($image, 40, 27, 22, $txt, $black); header("content-type:image/jpeg"); imagejpeg($image); imagedestroy($image); ?> I'm building a site similiar to a web forum.
The code is all done, this is how it works:
CREATING POST:
------------------------
In PHP: Create Post -> Upload Images -> Remake Images (For security) -> Create Thumbnails (saved in uploads folder with unique name) With DATABASE: I have a table called "images" which tracks user uploaded images: uploaded_by_username (stores who posted it) image_status (tracking whether user aborted upload) thumbnail_confirm (tracking whether thumbnail generated successfully) post_association (tracking the post that the images go to) image_name (the image filename in uploads filefolder) time (unix time-stamp of upload tracking for admin purposes) DELETING POST: ------------------------ In PHP: Move all images into a "deleted_images" folder ( I'm afraid to use "unlink") With DATABASE: Delete all associated images from images table ( Is this risky? Should I use a second table and transfer the images? ) Anyhow, feedback appreciated in regards to how I designed this. Is this acceptable for the industry? This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=321638.0 My string is like this: line 1 line 2 .... line 3453 line 3454 etc... I want to split the string into chunks of 500 lines, do something with those chunks and then reassamble the main $string again. The last chunk doesn't need to be 500 lines it can be less. How can I do it? In the following code only one image is draggable.How can i make multible image in toolbar to be draggable dynamically?Anyone help me? <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Prototype</title> <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.2.min.js"></script> <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script> <style> body{padding:20px;} #container{ border:solid 1px #ccc; margin-top: 10px; width:350px; height:350px; } #toolbar{ width:350px; height:35px; border:solid 1px blue; } </style> <script> $(function(){ // get a reference to the house icon in the toolbar // hide the icon until its image has loaded var $house=$("#house"); $house.hide(); // get the offset position of the kinetic container var $stageContainer=$("#container"); var stageOffset=$stageContainer.offset(); var offsetX=stageOffset.left; var offsetY=stageOffset.top; // create the Kinetic.Stage and layer var stage = new Kinetic.Stage({ container: 'container', width: 350, height: 350 }); var layer = new Kinetic.Layer(); stage.add(layer); // start loading the image used in the draggable toolbar element // this image will be used in a new Kinetic.Image var image1=new Image(); image1.onload=function(){ $house.show(); } image1.src="http://vignette1.wikia.nocookie.net/angrybirds/images/b/b6/Small.png/revision/latest?cb=20120501022157"; // make the toolbar image draggable $house.draggable({ helper:'clone', }); // set the data payload $house.data("url","house.png"); // key-value pair $house.data("width","32"); // key-value pair $house.data("height","33"); // key-value pair $house.data("image",image1); // key-value pair // make the Kinetic Container a dropzone $stageContainer.droppable({ drop:dragDrop, }); // handle a drop into the Kinetic container function dragDrop(e,ui){ // get the drop point var x=parseInt(ui.offset.left-offsetX); var y=parseInt(ui.offset.top-offsetY); // get the drop payload (here the payload is the image) var element=ui.draggable; var data=element.data("url"); var theImage=element.data("image"); // create a new Kinetic.Image at the drop point // be sure to adjust for any border width (here border==1) var image = new Kinetic.Image({ name:data, x:x, y:y, image:theImage, draggable: true, // restrict to allow horizontal dragging only dragBoundFunc: function(pos) { // if(pos.x<this.minX){ pos.x=this.minX; } // this.minX=pos.x; return { x: pos.x, y: this.getAbsolutePosition().y } } }); layer.add(image); layer.draw(); } }); // end $(function(){}); </script> </head> <body> <div id="toolbar"> <img id="house" width=32 height=32 src="http://vignette1.wikia.nocookie.net/angrybirds/images/b/b6/Small.png/revision/latest?cb=20120501022157"><br> </div> <div id="container"></div> </body> </html> Edited by Biruntha, 06 January 2015 - 08:10 AM. I basically have a PHP Search Form, and when a user fills in a form it outputs the results. Each result displays a image of a property, how could i make them images have their own unique link which will take them directly to the page of the property being shown? Im using PHP and mySQL tables Any help is appreciated, Thank You. Heres the PHP that outputs the results: Code: [Select] <?php require_once 'mstr_ref.php'; function san($input){ if(get_magic_quotes_gpc()){ $input=stripcslashes($input); } $output = mysql_real_escape_string($input); return $output; } if(isset($_POST['submit'])){ $pVars = array('area'=>$_POST['areas'], 'propType'=>$_POST['prop_type'], 'saleType'=>$_POST['ptype'], 'minB'=>$_POST['min_bedrooms'], 'maxB'=>$_POST['max_bedrooms'], 'minP'=>$_POST['min_price'], 'maxP'=>$_POST['max_price']); foreach ($pVars as $k=>$v){ $v = san($v); } $sql = new makeQuery(); $sql->manAdd('location_id', $pVars['area']); if($pVars['propType'] != 'Any'){ $sql->manAdd('catagory_id', $pVars['propType']); } if ($pVars['maxB'] > 0){ $sql->manAdd('bedrooms', $pVars['maxB'], '<='); } if($pVars['minB'] > 0){ $sql->manAdd('bedrooms',$pVars['minB'],'>='); } if($pVars['saleType'] != 'Any'){ if($pVars['saleType'] == "forsale"){ $sql->manAdd('market_type', 'sale'); if($pVars['minP'] != 0){ $pVars['minP'] = $pVars['minP'] * 1000; } if($pVars['maxP'] != 0){ $pVars['maxP'] = $pVars['maxP'] * 1000; } } if($pVars['saleType'] == 'forrent'){ $sql->manAdd('market_type', 'rent'); } } $qry = $sql->sqlStart.$sql->stmt.'Group By property.id'; $results = mysql_query($qry) or die (mysql_error()."<br />|-|-|-|-|-|-|-|-|-|-|-|-<br />$qry"); if(mysql_num_rows($results) < 1){ die ("Sorry, No Results Match Your Search."); } while($row = mysql_fetch_assoc($results)){ echo '<div class="container" style="float:left;">'; echo '<div class="imageholder" style="float:left;">'; echo "<img class='image1' src='{$row['image_path']}' alt='{$row['summary']}'> <br />"; echo '</div>'; echo '<div class="textholder" style="font-family:helvetica; font-size:14px; float:left; padding-top:10px;">'; echo "{$row['summary']}"; echo "<span style=\"color:#63be21;\"><br><br><b>{$row['bedrooms']} bedroom(s) {$row['bathrooms']} bathroom(s) {$row['receptions']} reception room(s)</b></span>"; if($row['parking'] != null){ echo "<span style=\"color:#63be21;\"><b> {$row['parking']} parking space(s)</b></span>"; } echo '</div>'; echo '<div style="clear:both"></div>'; } } else{ echo "There was a problem, please click<a href='index.php'> Here </a>to return to the main page and try again"; } ?> Folks, I need help (Php code ) to generate a Dynamic Text on a Base Image. What i want to do is, to make this Image as header on my Site and to make this Header Specific to a Site, i want to Add the Domain Name on the Lower Left of the Image. Got the Idea? Here is the Image link: Quote http://img27.imageshack.us/i/shoppingheader1.jpg/ PHP Variable that holds the Domain name is: $domain All i need the Dynamic PHP Codes that i can put on all my sites to generate this Text on Image (Header) Dynamically... May Anyone Help me with this Please? Cheers Natasha T. Okay so my news script is set to view only 10 pieces of news. But I want it so that it starts a new page once I have more than 10 pieces of news. Code: [Select] <?php require("functions.php"); include("dbconnect.php"); session_start(); head1(); body1(); new_temp(); sotw(); navbar(); $start = 0; $display = 10; $query = "SELECT * FROM news ORDER BY id DESC LIMIT $start, $display"; $result = mysql_query( $query ); if ($result) { while( $row = @mysql_fetch_array( $result, MYSQL_ASSOC ) ) { news_box( $row['news'], $row['title'], $row['user'], $row['date'], $row['id'] ); } mysql_free_result($result); } else { news_box( 'Could not retrieve news entries!', 'Error', 'Error', 'Error'); } footer(); mysql_close($link); ?> I tried a few things but they failed....miserably. Hey! I was wondering if anyone had a really nice login tutorial that teach to make a secure login that is easy to use. Also, it would be best if it checked the other files as a normal logincheck.php does, but it gotta fit the login of course Anyone ? I have a SQL statement which is difficult to use PDO on, it might not even be possible to do.
So I'm filtering it like this:
$search = $_GET['search']; $search = preg_replace("/[^A-Za-z0-9]/", " ", $search); $search = $mysqli->real_escape_string($search);Will this result in an acceptable level of security? Edited by anderson_catchme, 16 September 2014 - 12:28 PM. I was wondering if this is faster or better performance. Each time a user submit's a post on my forum I will make it +1 the .txt file on my main server directory called test.txt, then I can just call that on my main forum index to show the amount of total posts our board has, instead of using mysql queries to sum all of it from the tables... good idea? or am i retarded? This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=347419.0 I've always had an issue needing to write and maintain script to validate both client side and sever side so a while back I wrote a validation class whose primary purpose was: Accept in its constructor a JSON string which is mostly identical to the jQuery validation option except it also included a "sanitize" property. For instance: {"rules": {"account": {"minlength": 6}}, "messages": {"account": {"minlength": "Six numbers are required"}, "sanitize":{"account":int}}. Provide the correct jQuery validation option so a form can be validated client side. Sanitize the form data server side. Validate the form data server side.I recently looked at the code and it is a train wreck. I used a single class and had a bunch of protected functions where some would validate per a given rule and return the message upon error and others would sanitize. For non-typical rules required by the specific application, I would extend the class and add them. Some of these added rules required other resources such as an entities primary key, a PDO connection, etc. While inheritance worked fine to add simple rules, it did not do so for the rules which needed other resources. Also, even though I used "final" on my base class methods, I never liked this single class of many methods as I couldn't use the same name for a given rule and sanitize method (i.e. would rather use digit and digit instead of digit and int). I am thinking of changing it to something like the following. While this is definitely better, I question whether I should be using traditional classes to define my standard and custom rules. Any recommendations? Thanks class Validator { protected $options, $rules=[ "digit"=>function($value, $prop, $name){ return /*validate and return error string or null*/; }, "minlength"=>"ect, etc" ]; public function __construct(string $json, \Closure ...$customRules=[]) { $this->options=json_decode($json); $this->rules=array_merge($this->rules, $customRules); } } class Application { public function someMethod() { $pdo=$this->pdo; $applicationCustomRules=[ 'someCustomRule'=>function($value, $prop, $name) use ($pdo) { return /*validate and return error string or null*/; } ]; $validator=new Validator($json, ...$applicationCustomRules); //Which can be used such as: $jQueryOptions=$validator->getJQueryOptions(); $validator->validate($data); $validator->validateProperty('account', $account); } }
This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=320875.0 I just made this mini class for hashing passwords, is this all there is to it? Setting a salt string, and hashing the string using something like sha1(md5($salt.$password)) Code: [Select] <?php class MyHash { private $salt = "a6B2yj90sZ34"; public function set_salt($salt){ $this->salt = $salt; } public function hash_string($string){ return sha1(md5($this->salt.$string)); } public function check_hashed_string($user_input, $correct_pass){ if($this->hash_string($user_input) == $correct_pass){ return true; }else{ return false; } } } ?> Can someone provide me with a good tutorial on how to create really nice looking buttons please. Not just crap ones, like real nice ones. XD Thanks in advance This topic has been moved to Other Programming Languages. http://www.phpfreaks.com/forums/index.php?topic=347880.0 I would realy like to study php, other than taking other codes and editing them i havnt got a clue. Let's say for an "entry-income or low-income" to get started with.
How should it look like when it comes to the skills?
Could it work out if somebody for example can program with "bind parameters" and OOP in PHP?
What are your recommendations?
Edited by glassfish, 26 October 2014 - 10:20 AM. |