/*** Goofy 2011-11-29
* Image processing: According to the passed coordinate parameters, x, y, w, h, are the selected x coordinate, y coordinate, w width, and h height in turn.
* Copy this area to the blank image created in the first step through the imagecopy() method
* Note that when creating an image, you must use imagecreatetruecolor() for true color, otherwise the image will be distorted using imagecreate()*/
- /**
- * Goofy 2011-11-29
- * Image processing: According to the passed coordinate parameters, x, y, w, h, are the selected x coordinate, y coordinate, w width, h height in turn
- * Through the imagecopy() method Copy this area to the blank image created in the first step
- * Note that when creating the image, you must use imagecreatetruecolor() for true color, otherwise the image will be distorted using imagecreate()
- */
- //The proportion passed from the page
- $scale=$_GET['scale'];
- //The following attributes are multiplied by the corresponding Scale
- $x=$_GET['x']*$scale;
- $y=$_GET['y']*$scale;
- $w=$_GET['w']*$scale;
- $h= $_GET['h']*$scale;
- //Source path
- $src=$_GET['src'];
- //Do you want to continue? If you do not continue to take screenshots of this picture, the source picture will be deleted
- $again="off";
- if(!empty($_GET['again'])){
- $again=$_GET['again'];
- }
- //The first step is to create an image based on the passed width and height parameters, and then fill the intercepted part into this area
- header("Content-type: image/jpeg");
- $target = @imagecreatetruecolor($w,$h)
- or die("Cannot Initialize new GD image stream");
- //The second step is to get the source image according to the path and create an image object using the source image
- $ source = imagecreatefromjpeg($src);
- //The third step, according to the passed parameters, select a part of the source image to fill in the image created in the first step
- imagecopy( $target, $source, 0, 0, $ x, $y, $w, $h);
- //The fourth step, save the image
- //Intercept and organize the new path
- $pos_path= strripos($src, "/");
- $newPath=substr( $src,0,$pos_path-strlen($src))."_new/";
- //Intercept and organize new names
- $pos_name=strripos($src, ".");
- $newName=substr($src ,0,$pos_name);
- $pos_name_= strripos($newName, "/");
- //The suffix ".jpg" is not added here temporarily to prevent duplicate files. If there are, they need to be renamed and added. It will be inconvenient
- $newName=substr($newName,$pos_name_-strlen($newName)+1)."_";
- //Generate pictures without suffix
- $file=$newPath.$newName;
- / /Append asc code to rename the file. You can also name it with random numbers, time, etc. I don’t need those naming methods for project requirements
- for($i=0;$i<26;$i++){
- //If the directory exists
- if(is_dir($newPath)){
- //If the file exists, continue looping until there are no files with the same name
- if(is_file($file.chr(97+$i).".jpg")){
- continue;
- }else{
- //Create file
- imagejpeg($target,$file.chr(97+$i).".jpg",100);
- //After file creation is completed, determine whether to delete the source file, off is Delete the source file
- if($again=="off"){
- unlink($src);
- unset($_SESSION['url']);
- }
- break;
-
- }
- }else{
- //Create Directory
- mkdir($newPath);
- //Create file
- imagejpeg($target,$file.chr(97+$i).".jpg",100);
- //After file creation is completed, determine whether to delete the source file, off is to delete the source file
- if($again=="off"){
- unlink($src);
- unset($_SESSION['url']);
- }
- break;
- }
- }
- //Jump Go to the homepage
- Header("Location: index.php");
- ?>
Copy code
|