PHP - Auto Adjust Width Image Creation But Set Height
Hey guys I have a small issue, i have an upload that resizes the image into thumbnail by max width and ratios the width based on that.
Here is my code
What I am wanting to do is instead upload the image with a max height and ratio the width proportionally. What variables do I have to reverse? Similar Tutorialsi am uploading image to s3 server and by php i am making a copy of that image on server , if i upload an image of 2.3 mb than the width of image is not coming but if i upload less size image like 26kb than it is showing the width of image so it is able to create the copy . here is my code of php : $s3 = new S3(awsAccessKey, awsSecretKey); $thumbId = uniqid(); $thumbId .= ".jpg"; $img = ''; if($imgType == "image/jpeg"){ $img = imagecreatefromjpeg($sourceUrl); }else if($imgType == "image/png"){ $img = imagecreatefrompng($sourceUrl); }else if($imgType == "image/gif"){ $img = imagecreatefromgif($sourceUrl); }else{ $img = imagejpeg($sourceUrl); } echo $width = imagesx( $img ); echo $height = imagesy( $img ); please tell me what is the problem with size of image.. regards rahul Hi Fellas, having a bit of a brain freeze here, i am trying to set a max width or height for a uploaded image, but my brain has frozen, maybe its the cold weather lol list($width,$height)=getimagesize($uploadedfile); $newwidth=250; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); basicly i want to find the biggest size of an image, beit width or height then set that size to 250... Any pointers here? I am not sure what to look for to even get started. If some one could help point me in the right direction that would be appreciated.
I created a customer system that tracks contracts and invoices ect. Where do I start if I would want a customer to be able to go to the website, sign up, and their own version of the system would be created.
Do I just write a script that creates a new database with the correct credentials? Do all of the users access the same files but just have different database. Do I have to copy the directory of files to a specific folder for each customer?
I know there must be tons of websites that once you sign up for example a calendar app that keeps your data seperate from everyone else.
Any help is appreciated.
Thanks
Jack
Hey guys! I have the following php code that grabs variables (and the browsed image) from Flash. //FLASH VARIABLES $Name = $_POST['Name']; $itemNumber = $_POST['itemNumber']; $filename = $_FILES['Filedata']['name']; $filetmpname = $_FILES['Filedata']['tmp_name']; $fileType = $_FILES["Filedata"]["type"]; $fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000); list($filename, $extension) = explode('.', basename($_FILES['Filedata']['name'])); $filename = $Name; $target = $filename . $itemNumber . "." . $extension; // Place file on server, into the images folder move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$target); This works perfect, but what I want to change is the width and height of the uploaded image. Any ideas/suggestions on how this could be done? Thanks in advance!! Cheers! I have folder with 100's images, how to find Height and width as Excel sheet? Okay, so here is the deal. Have a table which stores image as blob files. Now i want to read the image width and height directly from the blob field. Is this possible and if yes, how? Things i tried so far; list($size[0],$size[1],$type, $attr) = getimagesize('image.php?i=26ddd45b02859e836d13d4b9fde34281'); print_r($size); $img = 'image.php?i=26ddd45b02859e836d13d4b9fde34281'; echo imagesy($img); image.php grabs the image from DB and show's it with header("Content-type: image/jpg"); It works for just showing the images with the <img> tag. Any ideas of help would be great! I am attempting to create an image and I have run into a snag. I want to add both text and another image to the image I am making. Here is the code so far minus unnecessary parts: header ("Content-type: image/png"); $name = $fetch_user['username']; $rank = $fetch_rank['rank_title']; $img_url = 'path''. $fetch_rank['rank_image']; $im = @imagecreatefrompng("$img_url") or die("Cannot Initialize new GD image stream"); // try changing this as well $font = 4; $width = imagefontwidth($font) * strlen($string) ; $height = imagefontheight($font) ; $im = imagecreatefrompng("image.png"); $x = imagesx($im) - $width ; $y = imagesy($im) - $height; $backgroundColor = imagecolorallocate ($im, 255, 255, 255); $textColor = imagecolorallocate ($im, 255, 255, 255); //imagestring ($im, $font, $x, $y, $string, $textColor); imagestring ($im, $font, 100, 10, $name, $textColor); imagestring ($im, $font, 100, 22, $rank, $textColor); imagepng($im); Everything works UNTIL I added in this part: $im = @imagecreatefrompng("$img_url") or die("Cannot Initialize new GD image stream"); Any idea what I am doing wrong? All that comes up is "Cannot Initialize new GD image stream"; and I know the URL's work. I am trying to create a basic image with GD library, but my browser says that the image cannot be displayed because it contains errors... I have no idea why. Here's my code: Code: [Select] switch($_GET['case']){ case "progressbar": header('Content-Type: image/jpeg'); $barWidth = 6; $barHeight = 14; $barPadding = 2; $imageWidth = ($barWidth * 10) + (10 * $barPadding); $imageHeight = ($barHeight + ($barPadding * 2)); $img = @imagecreate($imageWidth, $imageHeight); $imgBorder = imagecolorallocate($img, 0, 0, 0); //imagefilledrectangle($img, 1, $imageHeight -1, $imageWidth - 1, $imageHeight - 1, $imgBorder); $output = "Hello, world!"; imagestring($img, 1, 4, 4, $output, $imgBorder); imagejpeg($img); imagedestroy($img); break; } I have a file called image.php that i use to create images and I use the URL image.php?case=progressbar. I was not sure on which board to put this thread, so please move it if there is a more appropriate board. I am wanting to create a website that displays images which I have put into a database. I would like the number of images on one page not to exceed 10, for example, and when the number of images in the database exceeds this number, a new page will be created. I would like it to function similar to Google Images where the number of pages is dictated by the number of images in the database. I cant figure out how to achieve this, so any pointers or thoughts would be great Thanks, Matlab is there a way to make the column width to try not have multiple lines if possible when pulling 200 rows from a database? Hi there. How can i set up a maximum width and height of a picture? For example: the limit is 400x400. So if the photo is 200x200 then it stays that way, however if a photo is 550x550 then it gets resized to 400x400. Hi People. Thanks for all the help on here in the past, you have been brilliant. I run the airfield cards.com website and have a script in the output page that is as follows. Code: [Select] To Embed this Card into your website, cut and paste the following code: <input name="generate" value="<? echo "<iframe src='http://www.airfieldcards.com/php/courtesy_card.php?id=".$id. "' ></iframe>";?>"> Now the way it shows on the site is like this Code: [Select] <iframe src='http://www.airfieldcards.com/php/courtesy_card.php?id=165' ></iframe> So, I look at the iframe code from google that should be cut and pasted into a website (obviously it's working code from google) Code: [Select] <iframe width="700" height="1500" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps/ms?msa=0&msid=203054009368331462137.0004aa731e7de2e86a0e0&ie=UTF8&t=h&vpsrc=0&ll=53.800651,-4.042969&spn=80.03397,61.435547&z=4&output=embed"></iframe><br /><small>View <a href="http://maps.google.co.uk/maps/ms?msa=0&msid=203054009368331462137.0004aa731e7de2e86a0e0&ie=UTF8&t=h&vpsrc=0&ll=53.800651,-4.042969&spn=80.03397,61.435547&z=4&source=embed" style="color:#0000FF;text-align:left">AirfieldCards.com</a> in a larger map</small> Now I have tried to take the code from the google iframe (width/height/scrolling/etc) and paste it into my source but it doesn't work. Here's how I have done it. Code: [Select] To Embed this Card into your website, cut and paste the following code: <input name="generate" value="<? echo "<iframe width="700" height="1500" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src='http://www.airfieldcards.com/php/courtesy_card.php?id=".$id. "' ></iframe>";?>"> Can someone please modify my fist lot of code so that I have the correct height and width settings (700 x 1500) Thanks in advance Regards Vince Gledhill Hi folks, I'm using this code to display a picture that is uploaded in a form. Code: [Select] print "<img src='http://www.coast2kosci.com/mylongrun/test/photo_uploads/$imgx' width='300' height='300' alt='Your photo' />"; At first I tried specifying only the width, without the height. But for tall photos, the display wasn't really what I was after. Then I specified both width and height, which results in a mis-scaled photo. Is there any way that I can specify the height and width atributes as a sort of maximum / or limiter. Ie: If the height is greater than the width, limit the height to 300, and if the width is greater than the height, limit the width to 300? Thanks for your time, Dave Hi Im working on a market place style website. the framework im using is called elgg. it uses an algoritm to find the right approximate width and height of an image thats being uploaded. but on my site, all heights and widths must be the same. this is difficult because some pictures have much greater width than height and some have much greater height. so whats the best algoritm to use to make an accurate thumbnail of all images uploaded? Thanks Hey guys, I am making a quotes siggy, code: <?php /** * @author Jragon * @copyright 2010 */ $textfile = "quotes.txt"; $quotes = array(); if (file_exists($textfile)) { $quotes = explode("\n", file_get_contents($textfile)); srand((float)microtime() * 10000000); $string = $quotes[array_rand($quotes)]; $string = wordwrap($string, 100, "\n", true); text_to_image($string, 800); } else { $string = "Sig file non-existant..."; } function text_to_image($text, $image_width, $colour = array(0, 244, 34), $background = array(0, 0, 0)) { $font = 5; $line_height = 15; $padding = 2; $text = wordwrap($text, ($image_width/10)); $lines = explode("\n", $text); $image = imagecreate($image_width, ((count($lines) * $line_height)) + ($padding * 2)); $background = imagecolorallocate($image, $background[48], $background[44], $background[44]); $colour = imagecolorallocate($image, $colour[0], $colour[1], $colour[2]); imagefill($image, 0, 0, $background); $i = $padding; foreach ($lines as $line) { imagestring($image, $font, $padding, $i, trim($line), $colour); $i += $line_height; } header("Content-type: image/jpeg"); imagejpeg($image); imagedestroy($image); exit; } ?> What i want it to do is have the lines the same legnth, and when a quote is smaller the image to shrink. Thanks jragon I have been searching since past 3 days and came across many functions on php.net and other sites but i am unable to get it to work. Because in my case already uploaded image names are coming out of database through a while loop. So not sure how to integrate those functions here. Its a very simple process, images are uploaded and stored in a gallery folder and their names are stored in database. Then these images are displayed through while loop as follows <?php $sql = "SELECT * FROM gallery"; $result = @mysql_query($sql) or die(mysql_error()); while($rows = @mysql_fetch_array($result)){ $file = $rows['filename']; ?> <img src="gallery/<?php echo $file; ?>" border="0" /> <br /> <?php } ?> But image dimension can be random so i want it to show in a fixed size of 150x150. I am looking for a very simple method to make that happen. Please help. Hello, I'm a complete PHP newb. I'm curious whether PHP is even the best solution for my problem. I'm trying to automatically generate an xml file with the following structu Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <portfolio> <categories> <category id="film">Films</category> <category id="photo">Photography</category> <category id="graphic">Graphic Design</category> <category id="web">Web Design</category> </categories> <items> <item> <thumbnail>img/photo/003_small.jpg</thumbnail> <preview>img/photo/003.jpg</preview> <category>photo,film</category> <description>Description goes here.</description> </item> <item> <thumbnail>img/photo/003_small.jpg</thumbnail> <preview>img/photo/003.jpg</preview> <category>film</category> <description>Description goes here.</description> </item> <item> <thumbnail>img/photo/003_small.jpg</thumbnail> <preview>img/photo/003.jpg</preview> <category>graphic,photo</category> <description>Description goes here.</description> </item> </items> </portfolio> (You can ignore the description as I can put that in manually after the fact) There are lots of images and I just know that theres a way to fascilitate a script for this repetitive task to read a directory of a folder named "img" - see that there are a few folders named "photo" "film" and "graphic" etc, pull the images out of them in their corresponding categories etc. I just need the initial generated script with thumbnails and all the attributes, I can do the final tweeks afterward. This is for http://www.zoomrix.com/#portfolio This is the code that I'm working from right now (gathered from a few sources) Code: [Select] <?php $path_to_image_dir = 'images2'; // relative path to your image directory $xml_string = <<<XML <?xml version="1.0" encoding="UTF-8"?> <items> </items> XML; $xml_generator = new SimpleXMLElement($xml_string); if ( $handle = opendir( $path_to_image_dir ) ) { while (false !== ($file = readdir($handle))) { if ( is_file($path_to_image_dir.'/'.$file) ) { $item = $xml_generator->addChild('item'); $item->addChild('thumbnail', $path_to_image_dir.'/thumbs/'.$file); $item->addChild('preview', $path_to_image_dir.'/'.$file); $item->addChild('category', 'photo'); $item->addChild('description', ' '); } } closedir($handle); } header("Content-Type: text/xml"); echo $xml_generator->asXML(); ?>(The above code could be ran he http://www.zoomrix.com/index5.php ) I just can't figure out how to include the <portfolio> and <category> tags, or how to reference a file structure to input for the category child (depending on what folder an image is in). All the help would be greatly appreciated, even if you point me to the right tutorial. Thanks, GeorgeKotelnikov www.zoomrix.com Im trying to write an image upload script which checks various elements of the image and then saves it and and a thumbnail into a folder. At the moment I am getting a white screen which makes me think I have a syntax error so I have come here to find some fresh eyes to help me out. Can anyone see any reason why this wouldn't be working? Form Code: [Select] <form enctype='multipart/form-data' action='upload_image.php' method='POST'> <table class='uploads-form'> <tr> <td><input name='image' type='file' /><input type='hidden' name'MAX_FILE_SIZE' value='5000000' /></td> </tr> <tr> <td><input type='submit' name='upload_image' value='Upload' /></td> </tr> </table> </form> php <?php error_reporting(E_ALL); ini_set("display_errors", 1); $images_location = "project_files/"; $thumbs_location = "project_thumbs/"; $thumb_width = "100"; $maximum_size = "5000000"; //Auto Thumbnail Function function create_thumbnail($source,$destination, $thumb_width) { $size = getimagesize($source); $width = $size[0]; $height = $size[1]; $x = 0; $y = 0; if($width> $height) { $x = ceil(($width - $height) / 2 ); $width = $height; } elseif($height> $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_image = imagecreatetruecolor($thumb_width,$thumb_width) or die('Cannot initialize new GD image stream'); $extension = get_image_extension($source); if($extension=='jpg' || $extension=='jpeg') $image = imagecreatefromjpeg($source); if($extension=='gif') $image = imagecreatefromjpeg($source); if($extension=='png') $image = imagecreatefromjpeg($source); imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width,$height); if($extension=='jpg' || $extension=='jpeg') imagejpeg($new_image,$destination); if($extension=='gif') $imagegif($new_image,$destination); if($extension=='png') imagepng($new_image,$destination); } //Get Extension Function function get_image_extension($name) { $name = strtolower($name); $i = strrpos($name,"."); if (!$i) { return ""; } $l = strlen($name) - $i; $extension = substr($name,$i+1,$l); return $extension; } //Random Name Function function random_name($length) { $characters = "abcdefghijklmnopqrstuvwxyz01234567890"; $name = ""; for ($i = 0; $i < $length; $i++) { $name .= $character[mt_rand(0, strlen($characters) - 1)]; } return "image-".$name; } //Check And Save Image if(isset($_POST['upload_image'])) { if($_FILES['image']['name'] == ""){ echo = "Please select the image you would like to upload by clicking browse"; } else{ $size=filesize($_FILES['image']['tap_name']); $filename = stripslashes($_FILES['image']['name']); $extension = get_image_extension($filename); if($size > $maximum_size) { echo = "Your file size exceeds the maximum file size!"; } else if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo = "Only the following extensions are allowed. 'jpg', 'jpeg', 'png', 'gif'."; } else { $image_random_name=random_name(15).".".$extension; $copy = @copy($_FILES['image']['tmp_name'], $images_location.$image_random_name); if (!$copy) { echo = "Error while uploadin your image! Please try again!"; } else{ create_thumbnail($images_location.$image_random_name,$thumbs_location.$image_random_name, $thumb_width); echo = "Your image has been uploaded!"; } } } } ?> is there a way to get the $image width?... the $image is not on my server so i cant use getimagesize().. e.g. $image = http://www.example.com/picture.jpg how do i get the width? I have a code that will get the value of amount from $_GET, and it adds it to an image I have stored. My problem is the that image I use is 32x32, but I need to add more height to it to make it look correct. The image is transparent so I'd need to keep that also. The code I have now works, but the value of amount is on top of the image where I don't want it to be. Here's my code. <?php header("Content-type: image/png"); $image = $_GET['image'] .'.png'; $img_handler = imageCreateFromPNG("./item images/" . $image); imagesavealpha($img_handler, true); $color = ImageColorAllocate($img_handler, 204, 156, 12); ImageString($img_handler, 2, 0, 0, $_GET['amount'], $color); ImagePng($img_handler); ImageDestroy($img_handler); ?> |