Jump to content

Recommended Posts

Hey guys

 

Need some help using ImageMagick, does anyone know how to do a simple resize?

 

All i need it to do is upload an image and then resize to a set value and saved to a users folder. I'll work out how to get it to the users folder and take in the dynamic sizes using simple php, but i just need some help on implementing the ImageMagick calls, does anyone have any experience in this server tech? I've trawled the support for it and am having real troubles understanding it!

 

So far i've got the image uploader and i just need to know how to add into this a line that calls ImageMagick and resizes, before saving?

 

Here's what i got so far:

 

 

<?php

$user = $_GET['user'];





if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  
  $filename = basename($_FILES['uploaded_file']['name']);
  $ext = substr($filename, strrpos($filename, '.') + 1);
  if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && 
    ($_FILES["uploaded_file"]["size"] < 100000000)) {
    
      $newname = dirname(__FILE__).'/images/'.$filename;




      if (!file_exists($newname)) {
        
        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
          
        
         
         
         echo "<meta http-equiv=\"refresh\" content=\"0;URL=profile.php?user=$user\">";
         
         
         
         
        } else {
           echo "Error: A problem occurred during file upload!";
        }
      } else {
         echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
      }
  } else {
     echo "Error: Only .jpg images under 350Kb are accepted for upload";
  }
} else {
echo "Error: No file uploaded";
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/198496-resizing-help-using-imagemagick/
Share on other sites

here's a snippet i yanked from one of my past projects...you should be able to integrate it:

$imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "images/".$imagename;
              move_uploaded_file($source, $target);
              
              $imagepath = $imagename;
              $save = "images/" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file

              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 300; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 

              $save = "images/sml_" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file

              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 80; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 

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.