PHP - Limit Height / Width Of Embedded Photo
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 Similar TutorialsHi 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. i 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? 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 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! 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? 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 have folder with 100's images, how to find Height and width as Excel sheet? 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 Unless buffer overflows or breaking out of code to perform a new command are problems that have been solved.... I am trying to figure out the proper PHP method for setting a boundary on a variable within a script. I have this variable $name which is fed a value from $_POST['name'] from a form field. Now this form field is limited in the HTML to accept only 20 characters, but someone could easily edit the form or outgoing post data. So I want to know how to limit the variable size in the script. In other languages it could be something like this: var name(20). So how do I do that in PHP? Ok, this is killing me, So I'm finally asking for help. I'm working on a website, which streams videofiles from external links. The site plays & allows you to download the videos from the same external link. I need to mask the url of these videos. At the moment, I have successfully masked the url when downloading. If you click the download image, rather than the path being http://externalsite.com/videofile.avi its http://mysitename.com/external.php?id=xx&mid=xx So that is nicely hidden. However, I am having a problem when it comes to the embedded player on the page. At the moment i am using flowplayer for flv & mp4 videos, and just the usual embed for avi videos. Flow players embed code is like this --------------------------------------------------- <a href="<?=$videoFile?>" style="display:block;width:740px;height:400px;" id="player"> </a> <script language="JavaScript"> flowplayer("player", "<?=url::base()?>flowplayer-3.2.5.swf", { clip: { autoPlay: false, autoBuffering: true } }); </script> ----------------------------------------- At the moment, the player only works if i put the url in this format: http://externalsite.com/videofile.avi and wont work in this format http://mysitename.com/external.php?id=xx&mid=xx all download.php does is check the file exists, sets the headers and prompts users to open or save. Why isnt this working with the player? Please see the attached external.php file for my heade info etc to hopefully shed some light on this I'm having a problem understanding how to import more than one photo in a list of up to 20 photos. I can only import 1 photo from a comma delimited csv with a pipe between each photo url. <? function getImg($value,$userid, $stocknum){ $photoStr = ''; if($value !=''){ $photoURLs = explode('|', $value); for($i=0; $i<count($photoURLs);$i++){ $url = $photoURLs[$i]; $j = $i+1; if (@copy($url, "../upload/".$userid."/".$userid."_".$stocknum."_".$j.".jpg")) { $photoStr .= $userid."_".$stocknum."_".$j.".jpg|"; } } } return $photoStr; } ?> And after csv and sql <? if($img){ $img = rtrim($img, '|'); $imgArray = explode('|', $img); $imgIndex = 1; foreach ($imgArray AS $imgItem){ $db->query("UPDATE `stockitem` SET img".$imgIndex."= '$imgItem' where stocknum='$stocknum'","" , __FILE__, __LINE__); $imgIndex++; } } ?> Any help would be appreciated. I found the following forum topic and have implemented the solution provided at the bottom: http://www.phpfreaks.com/forums/index.php?topic=310258.0 Code: [Select] <?php $cnx = fopen("data/Book1.csv", "r"); //open example.csv echo("<table>\n\t<tbody>\n"); // echo the table while (!feof ($cnx)) { // while not end of file $buffer = fgets($cnx); // get contents of file (name) as variable $values = explode(",", $buffer); //explode "," between the values within the contents echo "\t\t<tr>\n"; for ( $j = 0; $j < count($values); $j++ ) { // echo("\t\t\t<td>$values[$j]</td>\n"); } echo"\t\t</tr>\n"; }; echo("\t</tbody>\n</table>"); fclose($cnx); //close filename variable ?> It works great. One question though - - what might it take to add an if/else statement that inserted the following for the first row in the CSV file ... Code: [Select] echo("\t\t\t<th>$values[$j]</th>\n"); ... and inserted the following for every row after the first ... Code: [Select] echo("\t\t\t<td>$values[$j]</td>\n"); This way I can better control my table through CSS. Any ideas? i want to be able to extract a string from a variable when an IMG tag is present and then use the link of the image to create an image tag of it's own to be displayed let's say i have a string $post which contains the following... (ignoring the quotations) here is some random text ["IMG"]http://www.somedomain.com/someimage.jpg[/"IMG"] here is some more random text how would i be able to extract the string inside the [IMG] tags and replace it with a different string in the same position excluding the [IMG] tags such as <img src=''http://www.somedomain.com/someimage.jpg"/> any recommendations on how i would be able to do this? I'm creating a learning tool where people can paste in information and learn about random subjects.
Ideally for a desktop view eg. widescreen, a browser/search engine is on the left, and the interface is on the right.
So I need to embed a browser, I have tried to embed Google but I think, obviously, that they do not permit that.
I have seen possible alternatives like Chromium or Mozilla not firefox, something else "Gecko?"
Anyway, aside from not knowing what a browser is... for example how else can you access a website without a browser, SSH right? But it's about parsing / interpreting the languages correctly...
So what options do I have? Or should I just optimize the website to be used split screen with a browser in a separate tab? (Currently what I'm doing).
i am in the process of creating an auction site. However the images do not show , just the placeholder. Can anyone indicate where I have gone wrong ?
i am using this script to enter the items into the Database
html>
<link rel="stylesheet" type="text/css" href="style.css">
if(isset($_GET["item"]))
if($_GET["item"]=="duplicate")
else if($_GET["item"]=="successful")
}
echo "<label for='item_name' class='label'>Item Name:</label>";
echo "</form>";
</body>
This script displays the items :
<html>
<link rel="stylesheet" type="text/css" href="style.css">
<body> session_start();
if(!isset($_SESSION["username"]))
else
$DBHOST = "localhost";
while($row = $result->fetch_assoc())
$iid = $row["item_id"];
$conn->close();
Hi all, i was wondering if someone could point me in the right direction on how to create the following. After someone uploaded a photo than Cut out only his head in a fixed square say 90x120 pix (of a larger picture). I have seen some on the internet but most of them use flash and i rather use javascript or no javascript at all. Can this be done with GD library for instance where you just give the coordinates and the size of a square. (if this can be done automated i love to hear it) I have seen one where someone should pinpoint the eyes. IF someone has experience with this or a general idea on what techniques to use let me know I bet there are loads of way to do this but the most light weight technique would be great. Something like the attached image I let my members to upload their photos, I m using the script I coded which checks the file extension, if the file extension is "jpg" ( if ($this->url['type'] == "image/jpg")) and less than 600kb it uploads. Otherwise it gives you a warning.. What I wonder is, do I face any unwanted results about this later ? Like someone uploads a virus or script then execute it and do something ? I have a large mysql table with over 2600 rows but only something like 350 unique names. what I'm trying to do is make a HTML table row and select element for every unique name. When the loop encounters a duplicate name, I want it to create new options for all of the duplicate rows. Here is a snippit of my table: Name D01_03 EMS Agency State 10002 Appropriate 2 digit FIPS code D01_04 EMS Agency County 10003 Appropriate 5 digit FIPS code D01_05 Primary Type of Service 5610 911 Response (Scene) with Transport Capability D01_05 Primary Type of Service 5620 911 Response (Scene) without Transport Capability D01_05 Primary Type of Service 5630 Air Medical So names D01_03 & D01_04, should have their own table rows and select elements and D01_05 should just be one row and one select element with all of the entries in their own option tag. The code (partially): $result = mysql_query("SELECT * FROM tblvalues") or die(mysql_error()); //Return the table row by row while($row = mysql_fetch_array($result)) { //Count occurances of element $multi = mysql_query("SELECT count(fldelement) FROM tblvalues WHERE fldelement = \"$row[fldelement]\"") or die(mysql_error()); $multicount = mysql_result($multi, "0"); $icount = $multicount - 1; if ($multicount > 1){ while($row = mysql_fetch_array($result) && $icount >= 0){ //Stuff to do for rows with duplicate names } } else { //Stuff to do for unique rows. } } So, what happens is the outer loop goes until it hits the inner loop, then the inner loop finishes off the remaining rows. i've tried adding a counter to decrement by 1 every iteration of the inner loop, and have it kick out when it hits 0, but that didn't work. Basically, what i think i'm trying to ask is, how do I make the outer loop skip over the lines that the inner loop covered OR how do I make the inner loop kick back out to the out loop when it is done with the duplicates? I'm really sorry for that long, confusing post, but I have been going crazy over this all day, any help would be more than appreciated! Hey Guys, I have a php script that update's franchise information using a mysql table. Note: Ter = Territory, ie. the territory that franchise covers. <?php include('config.php'); if (isset($_GET['Ter']) ) { $ter = (int) $_GET['Ter']; if (isset($_POST['submitted'])) { //Photo Upload //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $photo =($_FILES['photo']['name']); //Pause Photo Upload foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } $sql= "UPDATE `ter` SET `Ter` = '{$_POST['Ter']}' , `BranchName` = '{$_POST['BranchName']}' , `BranchAddress` = '{$_POST['BranchAddress']}' , `BranchTel` = '{$_POST['BranchTel']}' , `BranchEmail` = '{$_POST['BranchEmail']}' , `BranchLink` = '{$_POST['BranchLink']}' , `Theme` = '{$_POST['Theme']}' , `LocalInfo` = '{$_POST['LocalInfo']}' , `BranchInfo` = '{$_POST['BranchInfo']}' , `photo` = '{$_POST['photo']}' WHERE `Ter` = '$ter' "; mysql_query($sql) or die(mysql_error()); //Unpause Photo Upload //Writes the photo to the server move_uploaded_file($_FILES['photo']['tmp_name'], $target); //End of Photo Upload echo (mysql_affected_rows()) ? "Edited Branch.<br />" : "Nothing changed. <br />"; } $row = mysql_fetch_array ( mysql_query("SELECT * FROM `ter` WHERE `Ter` = '$ter' ")); ?> In phpmyadmin I can see my table and it has the correct image name displayed in the photo column. So you would assume its worked. But when I look in the 'images/' location no image has been uploaded. So I think there is an error with the upload part but cant figure out whats wrong. Cheers, S |