Heim >php教程 >php手册 >php+jquery在线切图代码[仿dedecms]

php+jquery在线切图代码[仿dedecms]

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-22 18:36:15989Durchsuche

php+jquery在线切图代码[防dedecms]


 


  
  Cropper
  
  
  
  
  
  
  
  
  
  
 
 
  

   

    AJAX image cropper - YUI-based
   

   
   

    

     Image :
     
    

    
    

    
    
   

   
   

    HTML Blog
   

  

 

上面为index.php文件
根据x,y,来用php重新绘图

 // get variables
 $imgfile = $_GET['image'];
 $cropStartX = $_GET['cropStartX'];
 $cropStartY = $_GET['cropStartY'];
 $cropW = $_GET['cropWidth'];
 $cropH = $_GET['cropHeight'];

 // Create two images
 $origimg = imagecreatefromjpeg($imgfile);
 $cropimg = imagecreatetruecolor($cropW,$cropH);

 // Get the original size
 list($width, $height) = getimagesize($imgfile);

 // Crop
 imagecopyresized($cropimg, $origimg, 0, 0, $cropStartX, $cropStartY, $width, $height, $width, $height);

 // force download nes image
 header("Content-type: image/jpeg");
 header('Content-Disposition: attachment; filename="'.$imgfile.'"');
 imagejpeg($cropimg);

 // destroy the images
 imagedestroy($cropimg);
 imagedestroy($origimg);
?>

这里是图片上的,

 
 if(!empty($_FILES["uploadImage"])) {
    // get file name
  $filename = basename($_FILES['uploadImage']['name']);
  
  // get extension
    $ext = substr($filename, strrpos($filename, '.') + 1);
    
    // check for jpg only
    if ($ext == "jpg") {
        // generate unique file name
     $newName = 'images/'.time().'.'.$ext;
     
     // upload files
         if ((move_uploaded_file($_FILES['uploadImage']['tmp_name'], $newName))) {
   
          // get height and width for image uploaded
          list($width, $height) = getimagesize($newName);
          
          // return json data
             echo '{"image" : "'.$newName.'", "height" : "'.$height.'", "width" : "'.$width.'" }';
         }
         else {
             echo '{"error" : "An error occurred while moving the files"}';
         }
    }
    else {
       echo '{"error" : "Invalid image format"}';
    }
 }
?>

教程地址:

欢迎转载!但请带上文章地址^^

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:用户权限管理代码 Nächster Artikel:无刷新登陆