PHP - Please Help Me Resize My Images
Hi guys, i have a form that uploads a school photo.
All i want to do is resize the image to its widest dimension of a width of 480 px and then obviously constrain the height. can anyone help me, ive tried to do this myself but when it comes to image properties i really struggle etc. heres my upload code. Code: [Select] <?php include("includes/connection.php"); // Where the file is going to be placed $schoolimage = "SchoolImages/"; //This path will be stored in the database as it does not contain the filename $currentdir = getcwd(); $path = $currentdir . '/' . $schoolimage; // Get the schoolid for the image and school linker table $schoolid = $_POST['schoolid']; //Get the school name $query = "SELECT * FROM school WHERE school_id = ".$schoolid; $result = mysql_query($query) or die("Error getting school details"); $row = mysql_fetch_assoc($result); $schoolname = $row['name']; //Use this path to store the path of the file in the database. $filepath = $schoolimage . $schoolname; //Create the folder if it does not already exist if(!file_exists('SchoolImages')) { if(mkdir('SchoolImages')) { echo 'Folder ' . 'SchoolImages' . ' created.'; } else { echo 'Error creating folder ' . 'SchoolImages'; } } //Store the folder for the course title. if(!file_exists( $filepath )) { if(mkdir( $filepath )) { echo 'Folder ' . $schoolname . ' created.'; } else { echo 'Error creating folder ' . $schoolname; } } // Where the file is going to be placed $target_path = $filepath; // Add the original filename to our target path. Result is "uploads/filename.extension" echo $target_path = $target_path . '/' . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded"; $filename = $_FILES['uploadedfile']['name']; //Store the filename, path other criteria in the database echo $query = "INSERT INTO image(image_id, name, path) VALUES(0, '$filename', '$filepath')"; //Perform the query $add = mysql_query($query, $conn) or die("Unable to add the image details to the database"); $imageid = mysql_insert_id(); //Store the filename, path other criteria in the database echo $query = "INSERT INTO image_school( image_id, school_id ) VALUES('$imageid', '$schoolid')"; //Perform the query $add = mysql_query($query, $conn) or die("Unable to add the image details to the database"); $message = 'Upload Successful'; } else { $message = 'There was an error uploading the file, please try again!'; } //Close the connection to the database mysql_close($conn); header("Location: add_school_photo_form.php? message={$message}&schoolid={$schoolid}"); //header("Location: add_school_photo_form.php? message=$message, schoolid=$schoolid"); exit(); ?> Id be eternially gratefull. Kind Regards Dean Similar TutorialsHey, I was wondering if there is a way to use PHP to resize images when they are a above a size limit? Im not referring to file size here, but rather the width by height ratio. As currently i upload images and echo them with: Code: [Select] style="width:250px;height:200px;" But this means my server is loading large images when i would rather resize them down upon upload to reduce loading times... Is this possible in php ? I Can't resize large images with imagecreatefromjpeg() I can load small 38kb images fine, when they get up 780+- or 1.3 mb +- (with a width of 2500px * x) I get the below error I also can upload the same pics in another file with out resizing(using imagecreatefromjpeg()) them and the script works fine. my max file upload size with xampp is 128mb / php5 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 191 extraneous bytes before marker 0xd9 in C:\xampp\htdocs\ed\phpsol\ch08\work\includes\create_thumb.inc.php on line 35 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'C:\xampp\tmp\php9596.tmp' is not a valid JPEG file in C:\xampp\htdocs\ed\phpsol\ch08\work\includes\create_thumb.inc.php on line 35 I'm basicly using a switch switch($type) { case 1: $source = @ imagecreatefromgif($original); if (!$source) { $result = 'Cannot process GIF files. Please use JPEG or PNG.'; } break; case 2: $source = imagecreatefromjpeg($original); <---- LINE 35 where $original is $original = $_FILES['image']['tmp_name']; break; I have code written for image uploading, but it doesn't allow multiple images on a single upload, and doesn't re-size. Anyone willing to share a good upload script that will do the following?: -Allow multiple image uploads (10+ per submission), -Re-size images on upload, and -Rename images. Thanks Brett hello I want download a file from another website and resize it to new size then reduce quality to 60% and save in on my host. this is my code about download and reduce quality. //images address $images1 = textbetween('<a href="','"',$text0); //save images $im = imagecreatefromjpeg($images1); // original image //reduce image quality imagejpeg($im, "/public_html/static/images/book/".$imagename.".jpg" , 60); // save to new image, third value is quality (0-100) if not specified its the default (75) can anyone help me to resize it? thank you Hi, I'm having to look hard for the right way to do this. Basically the image is sent to the database, and is called to be put in a table, but the images are all different sizes, i would like them all one size, whats the best way to do this with my existing script: Code: [Select] <?php error_reporting(E_ALL); ini_set("display_errors", 1); echo '<pre>' . print_r($_FILES, true) . '</pre>'; //This is the directory where images will be saved $target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; $target = $target . basename( $_FILES['upload']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['upload']['name']); // Connects to your Database mysql_connect("***", "***", "***") or die(mysql_error()) ; mysql_select_db("***") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `Companies` (company_name, basicpackage_description, location, postcode, upload) VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; echo mysql_error(); //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> I did a tutorial on uploading a profile pic and also did a tutorial on an image re-size class. The only thing is the tutorial on the re-size class is done without using a form which is pointless. Can someone help me integrate this into the profile pic tutorial? Here's a link to the re-size tutorial. http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/comment-page-3/#comment-401884 index.php <?php session_start(); //include the class include("resize-class.php"); //1 initialize / load image $resizeObj = new resize('sample.jpg'); //2 Resize image (options: exact, potrait, landscape, auto, crop) $resizeObj -> reseizeImage(150,100, 'crop'); //3 Save image $resizeObj -> saveImage('sample-resized.gif', 100); include "connect.php"; $_SESSION['username']='Anomalous'; $username = $_SESSION['username']; if ($_POST['submit']) { //get file attributes $name = $_FILES['myfile']['name']; $tmp_name = $_FILES['myfile']['tmp_name']; if ($name) { //start upload process $location = "avatars/$name"; move_uploaded_file($tmp_name,$location); $query = mysql_query("UPDATE users SET image='$location' WHERE username='$username'"); die("Your profile pic has been uploaded! <a href='view.php'>My Profile</a>"); } else die("Please select a file!"); } echo "Welcome, ".$username."!<p>"; echo "Upload your image: <form action='index.php' method='POST' enctype='multipart/form-data'> File: <input type='file' name='myfile'> <input type='submit' name='submit' value='Upload!'> </form>"; ?> resize-class.php <?php # ========================================================================# # # Author: Jarrod Oberto # Version: 1.0 # Date: 17-Jan-10 # Purpose: Resizes and saves image # Requires : Requires PHP5, GD library. # Usage Example: # include("classes/resize_class.php"); # $resizeObj = new resize('images/cars/large/input.jpg'); # $resizeObj -> resizeImage(150, 100, 0); # $resizeObj -> saveImage('images/cars/large/output.jpg', 100); # # # ========================================================================# Class resize { // *** Class variables private $image; private $width; private $height; private $imageResized; function __construct($fileName) { // *** Open up the file $this->image = $this->openImage($fileName); // *** Get width and height $this->width = imagesx($this->image); $this->height = imagesy($this->image); } ## -------------------------------------------------------- private function openImage($file) { // *** Get extension $extension = strtolower(strrchr($file, '.')); switch($extension) { case '.jpg': case '.jpeg': $img = @imagecreatefromjpeg($file); break; case '.gif': $img = @imagecreatefromgif($file); break; case '.png': $img = @imagecreatefrompng($file); break; default: $img = false; break; } return $img; } ## -------------------------------------------------------- public function resizeImage($newWidth, $newHeight, $option="auto") { // *** Get optimal width and height - based on $option $optionArray = $this->getDimensions($newWidth, $newHeight, $option); $optimalWidth = $optionArray['optimalWidth']; $optimalHeight = $optionArray['optimalHeight']; // *** Resample - create image canvas of x, y size $this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight); imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height); // *** if option is 'crop', then crop too if ($option == 'crop') { $this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight); } } ## -------------------------------------------------------- private function getDimensions($newWidth, $newHeight, $option) { switch ($option) { case 'exact': $optimalWidth = $newWidth; $optimalHeight= $newHeight; break; case 'portrait': $optimalWidth = $this->getSizeByFixedHeight($newHeight); $optimalHeight= $newHeight; break; case 'landscape': $optimalWidth = $newWidth; $optimalHeight= $this->getSizeByFixedWidth($newWidth); break; case 'auto': $optionArray = $this->getSizeByAuto($newWidth, $newHeight); $optimalWidth = $optionArray['optimalWidth']; $optimalHeight = $optionArray['optimalHeight']; break; case 'crop': $optionArray = $this->getOptimalCrop($newWidth, $newHeight); $optimalWidth = $optionArray['optimalWidth']; $optimalHeight = $optionArray['optimalHeight']; break; } return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight); } ## -------------------------------------------------------- private function getSizeByFixedHeight($newHeight) { $ratio = $this->width / $this->height; $newWidth = $newHeight * $ratio; return $newWidth; } private function getSizeByFixedWidth($newWidth) { $ratio = $this->height / $this->width; $newHeight = $newWidth * $ratio; return $newHeight; } private function getSizeByAuto($newWidth, $newHeight) { if ($this->height < $this->width) // *** Image to be resized is wider (landscape) { $optimalWidth = $newWidth; $optimalHeight= $this->getSizeByFixedWidth($newWidth); } elseif ($this->height > $this->width) // *** Image to be resized is taller (portrait) { $optimalWidth = $this->getSizeByFixedHeight($newHeight); $optimalHeight= $newHeight; } else // *** Image to be resizerd is a square { if ($newHeight < $newWidth) { $optimalWidth = $newWidth; $optimalHeight= $this->getSizeByFixedWidth($newWidth); } else if ($newHeight > $newWidth) { $optimalWidth = $this->getSizeByFixedHeight($newHeight); $optimalHeight= $newHeight; } else { // *** Sqaure being resized to a square $optimalWidth = $newWidth; $optimalHeight= $newHeight; } } return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight); } ## -------------------------------------------------------- private function getOptimalCrop($newWidth, $newHeight) { $heightRatio = $this->height / $newHeight; $widthRatio = $this->width / $newWidth; if ($heightRatio < $widthRatio) { $optimalRatio = $heightRatio; } else { $optimalRatio = $widthRatio; } $optimalHeight = $this->height / $optimalRatio; $optimalWidth = $this->width / $optimalRatio; return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight); } ## -------------------------------------------------------- private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight) { // *** Find center - this will be used for the crop $cropStartX = ( $optimalWidth / 2) - ( $newWidth /2 ); $cropStartY = ( $optimalHeight/ 2) - ( $newHeight/2 ); $crop = $this->imageResized; //imagedestroy($this->imageResized); // *** Now crop from center to exact requested size $this->imageResized = imagecreatetruecolor($newWidth , $newHeight); imagecopyresampled($this->imageResized, $crop , 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight , $newWidth, $newHeight); } ## -------------------------------------------------------- public function saveImage($savePath, $imageQuality="100") { // *** Get extension $extension = strrchr($savePath, '.'); $extension = strtolower($extension); switch($extension) { case '.jpg': case '.jpeg': if (imagetypes() & IMG_JPG) { imagejpeg($this->imageResized, $savePath, $imageQuality); } break; case '.gif': if (imagetypes() & IMG_GIF) { imagegif($this->imageResized, $savePath); } break; case '.png': // *** Scale quality from 0-100 to 0-9 $scaleQuality = round(($imageQuality/100) * 9); // *** Invert quality setting as 0 is best, not 9 $invertScaleQuality = 9 - $scaleQuality; if (imagetypes() & IMG_PNG) { imagepng($this->imageResized, $savePath, $invertScaleQuality); } break; // ... etc default: // *** No extension - No save. break; } imagedestroy($this->imageResized); } ## -------------------------------------------------------- } ?> view.php <?php include ("connect.php"); $username = $_SESSION['username']; echo $username; $query = mysql_query("SELECT * FROM users WHERE username='$username'"); if (mysql_num_rows($query)==0) die("user not found"); else { $row = mysql_fetch_assoc($query); $location = $row['image']; echo "<img src='$location'>"; } ?> connect.php <?php session_start(); mysql_connect('localhost', 'root', 'root'); mysql_select_db('DB'); ?> The below code inserts image details to db and uploads pic to folder, can anyone show me how to resize it aswell. please Code: [Select] <?php include("includes/connection.php"); // Where the file is going to be placed $schoolimage = "SchoolImages/"; //This path will be stored in the database as it does not contain the filename $currentdir = getcwd(); $path = $currentdir . '/' . $schoolimage; // Get the schoolid for the image and school linker table $schoolid = $_POST['schoolid']; //Get the school name $query = "SELECT * FROM school WHERE school_id = ".$schoolid; $result = mysql_query($query) or die("Error getting school details"); $row = mysql_fetch_assoc($result); $schoolname = $row['name']; //Use this path to store the path of the file in the database. $filepath = $schoolimage . $schoolname; //Create the folder if it does not already exist if(!file_exists('SchoolImages')) { if(mkdir('SchoolImages')) { echo 'Folder ' . 'SchoolImages' . ' created.'; } else { echo 'Error creating folder ' . 'SchoolImages'; } } //Store the folder for the course title. if(!file_exists( $filepath )) { if(mkdir( $filepath )) { echo 'Folder ' . $schoolname . ' created.'; } else { echo 'Error creating folder ' . $schoolname; } } // Where the file is going to be placed $target_path = $filepath; // Add the original filename to our target path. Result is "uploads/filename.extension" echo $target_path = $target_path . '/' . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded"; $filename = $_FILES['uploadedfile']['name']; //Store the filename, path other criteria in the database echo $query = "INSERT INTO image(image_id, name, path) VALUES(0, '$filename', '$filepath')"; //Perform the query $add = mysql_query($query, $conn) or die("Unable to add the image details to the database"); $imageid = mysql_insert_id(); //Store the filename, path other criteria in the database echo $query = "INSERT INTO image_school( image_id, school_id ) VALUES('$imageid', '$schoolid')"; //Perform the query $add = mysql_query($query, $conn) or die("Unable to add the image details to the database"); $message = 'Upload Successful'; } else { $message = 'There was an error uploading the file, please try again!'; } //Close the connection to the database mysql_close($conn); header("Location: add_school_photo_form.php? message={$message}&schoolid={$schoolid}"); //header("Location: add_school_photo_form.php? message=$message, schoolid=$schoolid"); exit(); ?> I am looking for a script that can change the width and height of an image when it is uploaded to our web site through a web form. Any help would be great. When i use the following script to upload and resize an image, it throws out errors (see after script) <?php $image = $_FILES['image']['name']; $uploaddir = "./images/$gender/"; $pext = getExtension($image); $pext = strtolower($pext); if (($pext != "jpg") && ($pext != "jpeg") && ($pext != "gif")) { print "<h1>ERROR</h1>Image Extension Unknown.<br>"; print "<p>Please upload only an image with the extension .jpg or .jpeg or .gif ONLY<br><br>"; print "The file you uploaded had the following extension: $pext</p>\n"; unlink($imgfile); exit(); } $imgsize = GetImageSize($image); /*== check size 0=width, 1=height ==*/ if (($imgsize[0] > 460) || ($imgsize[1] > 345)) { $tmpimg = tempnam("/tmp", "MKUP"); system("djpeg $image >$tmpimg"); system("pnmscale -xy 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile"); unlink($tmpimg); } $rand = rand(0,9999999); $date = DATE("d.m.y"); $image_name=$date.$id.$rand.'.'.$extension; $final_filename = str_replace(" ", "_", $image_name); $newfile = $uploaddir . "/$final_filename"; if (is_uploaded_file($image)) { if (!copy($imgfile,"$newfile")) { print "Error Uploading File."; exit(); } } unlink($image); print("<img src=\"$newfile\">"); ?> errors: Quote Warning: getimagesize((R)Photo-0027.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/bumwarsc/public_html/images.php on line 77 Warning: unlink((R)Photo-0027.jpg) [function.unlink]: No such file or directory in /home/bumwarsc/public_html/images.php on line 126 I want to resize an image to fit within a rectangle. Lets say my rectangle is 400 wide and 200 tall. My image is 300x300. It should take, and make the rectangle 200 tall, then scale the width accordingly. I wrote a function a while back that resizes inside a square, but that was a little easier, since you know to constrain by height if height is greater than width, and to constrain by width if width is greater than height. $w = $stats[0]; $h = $stats[1]; if($dim){ // constrain image if($w > $h){ $h = ($h / $w) * $dim; $w = $dim; } else { $w = ($w / $h) * $dim; $h = $dim; } } Thats my code to constrain inside a box. It gets the starting h and w from $stats, which is loaded from getimagesize. Then it sets a new h and w based on dim, which is the size of the box. The new version will need dimW and dimH, instead of just dim. Can anyone help me out? I want to resize both width and height of the thumb pic this is the php code <?php $id_member=$_SESSION['rid']; if(!empty($foto1_name)) { $nama_file=$foto1_name; $anton->sekur_upload($nama_file); if($valid) { $abpath = "conf/i/"; @copy($foto1, $abpath."/".$foto1_name); $abang_dom=$abpath."/".$foto1_name; list($width, $height) = getimagesize($abang_dom); if($width>200) { make_thumb("$abpath/$foto1_name","conf/i/thumb/$foto1_name",200); } else { $tujuan="conf/i/thumb/".$foto1_name; rename($abang_dom, $tujuan); } } $foto_old_name=$foto1_name; $foto1_name=$id_member."_".$foto1_name; $foto1_name=strtolower($foto1_name); $foto1_name=str_replace(' ', '', $foto1_name); $asal1="conf/i/".$foto_old_name; $asal2="conf/i/thumb/".$foto_old_name; $tujuan1="conf/i/".$foto1_name; $tujuan2="conf/i/thumb/".$foto1_name; rename($asal1, $tujuan1); rename($asal2, $tujuan2); } I want to set the size to 100 x 100, which part of the code that I need to edit? Hello, I use this code to resize images: <?php function makeresize($dir,$pic,$n,$t){ @list($width, $height, $type, $attr) = @getimagesize($pic); $max_w = 700; $max_h = 500; $ratio = @min($max_w/$width,$max_h/$height); if ($ratio < 1){ $w = @floor($ratio*$width); $h = @floor($ratio*$height); $thumb = @imagecreatetruecolor($w,$h); if ($t == 'image/jpeg'){$temp = @imagecreatefromjpeg($pic);} elseif ($t == 'image/gif'){$temp = @imagecreatefromgif($pic);} elseif ($t == 'image/png'){$temp = @imagecreatefrompng($pic);} @imagecopyresampled($thumb,$temp,0,0,0,0,$w,$h,$width,$height); if ($t == 'image/jpeg'){@imagejpeg($thumb,"$dir/".$n, 100);} elseif ($t == 'image/gif'){@imagegif($thumb,"$dir/".$n, 100);} elseif ($t == 'image/png'){@imagepng($thumb,"$dir/".$n, 8);} } } ?> the code that calls the function above is: $tipi_consentiti = array("image/gif","image/jpeg","image/png","image/pjpeg"); // form data $titolo = @addslashes($_POST['titolo']); $descrizione = @addslashes($_POST['descrizione']); $nome = @addslashes($_FILES['imagefile']['name']); $path = $carfoto_user . stripslashes($nome); $tipo = @addslashes($_FILES['imagefile']['type']); ............ if ((@in_array($_FILES['imagefile']['type'], $tipi_consentiti))&& ($_FILES["imagefile"]["size"] < 2200000)){ // copio il file nella cartella delle immagini @copy ($_FILES['imagefile']['tmp_name'], $carfoto_user . $nome); $nomenew = $t."_".$nome; @makeresize($carfoto_user,$path,$nomenew,$tipo); unlink($carfoto_user.$nome); well. everything works fine, but now I want to paste the resized image produced on another image that has a fixed size. It is necessary for javascript gallery output (if the image is too small). How can I change the above code to do this. Can you help me? Thanks in advance..sorry for my english please Hi! I'm looking for a script that can do the following: upload one or preferably fx. five image files(jpg) resizes them to a specific size if they exceeds that size. create a thumbnail No files above 100kb can be uploaded. uploaded and/or processed files must be renamed with a unique file name. Work with php5 I have searched the internet for a script like that, but I can't find one that matches my needs. Also, the code must include good comments and nott be to hard to understand. So as basic code as possible. How can I resize an image that i'm showing and rather than saving it, just output the file? And would this vary if I was to be first calling the image through AJAX? I am having a lot of trouble finding material to help me with this problem. I am using cakephp 1.2. What i want to be able to do is give users the ability to upload an avatar. For form is quite basic (takes the data and updates the corresponding record in the database) but I need to add in a file upload form object so the user can pick an image then i my code to be able to take that image and save it in multiple sizes and finally to save the image name and extension (ex: image.jpg) in to the database table. If anyone can help me with this it would be such a massive help. What I want to do is to upload an image, find out what the size is and then make the height=377, and keep with width at the same ratio. this is my upload code: Code: [Select] <?php error_reporting(0); mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("myDB") or die(mysql_error()); $picture = $_FILES['image']['tmp_name']; $brand = $det['pro_name']; $year = $det['pro_vint']; $story = $det['pro_story']; $description = $det['pro_desc']; $why = $det['pro_why']; $intensity = $det['F12']; $body = $det['F11']; $sweet = $det['F8']; $acid = $det['F9']; $oak = $det['F10']; $lcbo = $det['lcbo_num']; $size = $det['pro_size']; $btl = $det['pro_btl']; $price = $det['pro_price']; $lto = $det['F7']; $audio = $det['wineAudio']; if(!isset($picture)) echo ""; else { $image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); $image_name = addslashes($_FILES['image']['name']); $image_size = getimagesize($_FILES['image']['tmp_name']); list($width, $height, $type, $attr) = getimagesize($_FILES['image']['tmp_name']); if($height != $width * 1.5 ){ echo "Image does not meet requirements"; }else{ if($image_size==FALSE) echo "This is not an Image"; else{ if(!$insert = mysql_query ("UPDATE `phpmy1_vincastweb_com`.`Sheet1` SET `image_name` = '".$image_name."', image='".$image."' WHERE `pro_id` ='".$id."'")) echo "Problem Uploading Image."; else{ $lastid = mysql_insert_id(); echo "Image Uploaded!<p />".$text."<p /><p /> Your Image:<p />"; $lastid = $id; echo "<img src='get_2.php?Product=$lastid' width='250' height='320' /><br />Click <a href='Agency/product3.php?Product=".$id."' target='_blank'>HERE</a> to view with Product" ; } } } } ?> right now I have it so that its at a ratio of height=3, and width=2...everything works fine but its not exactly what i want.. any ideas ? Hi Guys, I have this script below which inserts the file name and path into my datebase and uploads the file into the customers folders (which is creates dynamically). The is no error checking as I want it to be as flexible as possible but mostly(99.999%) the files I upload are JPEG and PDF's. I would like my script to be able to resize the files above automatically to be smaller. Please is this possible thanks! Here is script: <?php //Will create a directory once a customer is clicked and will not if page is refreshed an so forth if (file_exists('customerUploads/' . $check_id . ', ' . $c_name . '')) { } else { mkdir('customerUploads/' . $check_id . ', ' . $c_name . ''); } ?> <?php //This php block of code will takecare of inserting the upload variables into the db if(isset($_POST['submitbutton'])) { $target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/'; $target_path = str_replace("'","",$target_path); $target_path = $target_path . basename( $_FILES['upload']['name']); $manager= mysql_real_escape_string($_POST['username']); $upload = $_FILES['upload']['name']; $upload = str_replace("'","",$upload); $check_id = mysql_real_escape_string($_POST['id']); $submitbutton= mysql_real_escape_string($_POST['submitbutton']); if($submitbutton) { if($manager&&$upload) { if (file_exists($target_path)) { echo $_FILES["upload"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["upload"]["tmp_name"],$target_path); echo "Stored in: " . 'customerUploads/' . $check_id . ', ' . $c_name . '/' . $_FILES["upload"]["name"]; $insert=mysql_query("INSERT INTO img_up (username,upload,id,target_path,img_date) VALUES ('$manager','$upload','$check_id','$target_path', now()) "); // Where the file is going to be placed $target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/'; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['upload']['name']); $target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/'; $target_path = $target_path . basename( $_FILES['upload']['name']); if (file_exists($target_path)) { echo $_FILES["upload"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["upload"]["tmp_name"],$target_path); echo "Stored in: " . 'customerUploads/' . $check_id . ', ' . $c_name . '/' . $_FILES["upload"]["name"]; } } } else { echo "There was an error uploading the file, please try again!"; } } header("location: mainupload_complete.php?id=$check_id"); } ?> hi, i want to resize the font-size in my website ussing php butt it doenst work why ?? can someone help me to get it working?? Code: [Select] <html> <head> <title>Een website naam.</title> </head> <!-- this doent work, this was a test to see ik ik works!! --> <style type='text/css'> html{ font-size: 300%; } </style> <!-- this is my php code for working with resize!! This must got to work !!! --> <!-- Start varible font-size --> <?php //start session Session_start(); $_SESSION['FontSize']='300'; // check default fontsize if($_SESSION['FontSize']=='') { ?> <style type='text/css'> body { font-size: 100%; } </style> <?php } else { echo "<style type='text/css'>body { font-size: ".$_SESSION['FontSize']."%; } </style>"; } ?> <!-- end varible font-size --> how can tell my wath i do wrong??? thnx, Hello, i have a textarea which can contains too long sentences in a row and many new lines i have a div which is auto height and retrieve each message from the textarea .. the thing is that i want to resize it so it can fit inside the width of the dive which is about 700px .. i tried getting all sentences between each newline and resize then if they are >80 chars and then add <br /> but the login doesnt seem correct.. how else can i achieve that? thanks. I am trying to replace image code and resize it at the same time but gave me error. Warning: getimagesize($1): failed to open stream: No such file or directory in C:\wamp\www\ . . . . . public function resize_Images($originalImage,$toWidth,$toHeight){ // Get the original geometry and calculate scales list($width, $height) = getimagesize($originalImage); $xscale=$width/$toWidth; $yscale=$height/$toHeight; // Recalculate new size with default ratio if ($yscale>$xscale){ $new_width = round($width * (1/$yscale)); $new_height = round($height * (1/$yscale)); } else { $new_width = round($width * (1/$xscale)); $new_height = round($height * (1/$xscale)); } // Resize the original image $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg ($originalImage); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } public function bhl_bbcodes($str) { $simple_search = array( '/\[img\](.*?)\[\/img\]/is', ); $simple_replace = array( '<img src="'.$this->resize_Images('$1', 700, 500).'" />', ); $str = preg_replace ($simple_search, $simple_replace, $str); return $str; } |