Jump to content

PHP Image Resize


dezkit

Recommended Posts

Hey, I have this code:

  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    } else {
    echo "<font color=\"red\" size=\"+1\">Image has been uploaded!</font><br><br>";
   if (file_exists("./uploads/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      } else {
     $filename = $_FILES["file"]["name"];
      move_uploaded_file($_FILES["file"]["tmp_name"], $target);
      $thumbn = $sein . "th-" . $fale;
      cropImage(83, 60, "$target", "$ext", "$thumbn");
      include("config.php");
      $thumbnailss = "th-".$fale;
      mysql_query("INSERT INTO gallery (thumb_url, full_url) VALUES('$thumbnailss', '$fale' ) ") or die(mysql_error());  
      }
    }

 

How do i make it so that the file is going to be re sized half its size? There are no tutorials on this, i have searched google, thanks guys.

Link to comment
Share on other sites

I have found this code:

<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

 

But how do i implement that code into my code? Thanks

Link to comment
Share on other sites

cropImage()? Are you using ImageMagick?

 

That's a function I created to make a thumbnail of the uploaded file, but this is what i want

 

user uploads an image (done)

uploaded image gets half sized and saved to /uploads/ (getting help from you guys!)

using my function cropImage() to crop the uploaded image and save the image to /uploads/ (done)

Link to comment
Share on other sites

I'm sorry for not understanding but when you say half sized, do you literally mean half of the bytes or half the resolution?  If it's resolution, just use the code you found without the header() line, and using a second parameter for imagejpeg() (http://www.php.net/imagejpeg if you haven't used this before).

 

If you need more help, I guess I could whip you up some code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.