Jump to content

Kazzie-D

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

About Kazzie-D

  • Birthday 01/08/1977

Contact Methods

  • Website URL
    http://www.therobinsonshouse.com

Profile Information

  • Gender
    Female
  • Location
    Cheshire, England UK

Kazzie-D's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the advice guys! Managed to get it to work ** amaze!** Thought I would post my code incase it might help someone else: // Resize image during upload if larger than maximum allowed size. Function createthumbnail($src=null) { $srcimg = imagecreatefromjpeg($src); // Get size of original image: $srcsize = getimagesize($src); // Specify maximum image width / height allowed: $my_size = 350; // If the original image width and height are greater than $my_size, resize to the maximum image width / height allowed: if($srcsize[0] > $my_size && $srcsize[1] > $my_size) { $dest_x = 350; $dest_y = (350 / $srcsize[0]) * $srcsize[1]; $thumbimg = imagecreatetruecolor($dest_x, $dest_y); imagecopyresampled($thumbimg,$srcimg,0,0,0,0,$dest_x,$dest_y, $srcsize[0], $srcsize[1]); imagejpeg($thumbimg,$src); } } Thanks for your help!
  2. Well, to cut a long story short, I am not currently able to use imagemagick to resize my images, so have managed to get my code working thus (with thanks to meomike2000!!): <?php Function createthumbnail($src=null) { $srcimg = imagecreatefromjpeg($src); $srcsize = getimagesize($src); $dest_x = 350; $dest_y = (350 / $srcsize[0]) * $srcsize[1]; $thumbimg = imagecreatetruecolor($dest_x, $dest_y); imagecopyresampled($thumbimg,$srcimg,0,0,0,0,$dest_x,$dest_y, $srcsize[0], $srcsize[1]); imagejpeg($thumbimg,$src); } //This is the directory where images will be saved $target = "pictures/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $name=$_POST['name']; $Title=$_POST['Title']; $Item=$_POST['Item']; $pic=($_FILES['photo']['name']); // Connects to your Database mysql_connect("host", "username", "password") or die(mysql_error()) ; mysql_select_db("database") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO table VALUES ('$id' , '$Title', '$Item', '$pic', '$name')") ; //Writes the photo to the server createthumbnail($_FILES['photo']['tmp_name']); if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['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."; } $query="SELECT * FROM newsarticles ORDER BY id DESC LIMIT 1"; $result=mysql_query($query); while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ ?> <table width="800" border="1" bordercolor="#0a50a1" bgcolor="#ffffff" align="center" cellpadding="0" cellspacing="0"><tr><td><table width="100%" border="0" bgcolor="#ffffff" align="center" cellpadding="8" cellspacing="0"> <tr> <td align="left"><? echo "<img src=http://www.website.com/pictures/".$row['photo'].">"; ?></td></tr> <tr><td align="left" style="font-family: verdana; font-size: .8em; color: #0a50a1"><b><? echo $row['Title'];?></b><br><br> <? echo $row['Item'];?></td></tr></table></td></tr></table> <? } ?> There is just one thing I still want to try and do; if the image to be uploaded is smaller than the required size (ie 350px) then I don't want it to be resized. I have been trying with something like or some combination of: if ($srcsize > 350){ createthumbnail($_FILES['photo']['tmp_name']); } else { just upload image!! But obviously I'm writing it wrong and also putting it in the wrong place!! Could someone point me in the right direction please before I tear my last hair out (lol!)
  3. Oh no, more options - thank you! LOL! Well I decided to start a poll here: http://www.phpfreaks.com/forums/index.php/topic,286915.msg1360370.html#msg1360370 To see what the general opinion is on image manipulation..... yes, I genuinely want to know !
  4. Am interested to see people's opinion on this one....am wanting to upload and resize images and wondering which is the most popular!
  5. Hi guys - thanks for the replies! Ah...I see that would make more sense. Thanks for the code - I will have a play with that tonight once my toddler is in bed (looking after a mad two year old and concentrating on PHP code do not mix!!!)
  6. Have been looking at this again....perhaps I need to call the 'SimpleImage.php' file from my page with the form on it? Something like: <?php if( isset($_POST['submit']) ) { include('SimpleImage.php'); $image = new SimpleImage(); $image->load($_FILES['photo']['tmp_name']); $image->resizeToWidth(150); $image->output(); } else { ?> <form enctype="multipart/form-data" action="add-resize.php" method="POST"> Title: <input type="text" name = "Title"><br> Article: <input type="text" name = "Item"><br> Photo: <input type="file" name="photo"><br> Name: <input type="text" name="name"><br> <input type="submit" name="submit" value="Add"> </form> <?php } ?> But I still haven't got it right! What am I missing?
  7. Kazzie-D

    Hello!

    Hi salathe - I'm sure I will be making a visit to regular expressions at some point during my steep PHP learning curve!
  8. Kazzie-D

    Hello!

    LOL! Oh dear....looks like I've got a bit of work on my hands RussellReal....well, I shall give it my best shot for you
  9. Kazzie-D

    Hello!

    LOL! Well I shall recommend you for promotion ha ha! I've been naughty already - I accidentally posted the same topic twice (computer hung during first one, didn't think it had worked!) Oops..... Anyway, thanks for the welcome!
  10. Sorry, didn't do it on purpose, my computer hung first time didn't think it had worked. Just trying to delete one!!!
  11. Resizing & Uploading an image I've been playing around with this for a while now. Basically what I want to do is a user uploads a picture to the server via a form. During the upload I would like the picture to be resized and saved (overwriting itself and saving the resized image). I've got some code; I can upload images to the server via a form, I can also resize images and save/overwrite the images. What I can't quite do is both at the same time! I have 3 pages, one is a basic html upload form. Another is this file which is called when image is uploaded (this also shows the resulting uploaded fields/image): //This is the directory where images will be saved $target = "pictures/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $name=$_POST['name']; $Title=$_POST['Title']; $Item=$_POST['Item']; $pic=($_FILES['photo']['name']); // Connects to your Database mysql_connect("localhost", "username", "password") or die(mysql_error()) ; mysql_select_db("database") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO table VALUES ('$id' , '$Title', '$Item', '$pic', '$name')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['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."; } $query="SELECT * FROM table ORDER BY id DESC LIMIT 1"; $result=mysql_query($query); while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ include('SimpleImage.php'); $image = new SimpleImage(); $image->load(pictures/$row['photo']); $image->resizeToWidth(350); $image->save(pictures/$row['photo']); ?> <table width="800" border="1" bordercolor="#0a50a1" bgcolor="#ffffff" align="center" cellpadding="0" cellspacing="0"><tr><td><table width="100%" border="0" bgcolor="#ffffff" align="center" cellpadding="8" cellspacing="0"> <tr> <td align="left"><? echo "<img src=http://www.domain/pictures/".$row['photo'].">"; ?></td></tr> <tr><td align="left" style="font-family: verdana; font-size: .8em; color: #0a50a1"><b><? echo $row ['Title'];?></b><br><br> <? echo $row['Item'];?></td></tr></table></td></tr></table> <br> <? } ?> And the last file is obviously the 'SimpleImage.php' page. I'm just really struggling getting the above code right. In it's present state it uploads the image and displays the fields and image, but does not resize it and throws up a lot of errors. I THINK(!) it's just how I've written the above file, I can't quite grasp what is wrong. Hope someone can give me a couple of pointers! Thanks! ;-)
  12. Kazzie-D

    Hello!

    Just wanted to say hello before I start posting - felt it kind of rude not to! I've been learning PHP for a couple of months and have been getting along OK - slowly but OK! I will no doubt be asking for a little help but hoping I will be able to help others too!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.