/ * Goofy 2011-11-29 * Image processing: According to the coordinates passed over the parameters, X,y,w,h, followed by the selected x-coordinate, y-coordinate, W-width, h-height through the imagecopy () Method copy the region to the blank image created in the first step , note that the Imagecreatetruecolor () True color is used when creating the image, otherwise the imagecreate () image will be distorted. free picture cut no scale
-
- /**
- * Goofy 2011-11-29
- * Image processing: According to the coordinate parameters passed, x,y,w,h, followed by the selected x-coordinate, y-coordinate, W-width, h-height
- * Copy the area to a blank image created in the first step by using the Imagecopy () method
- * Note that when creating an image, use Imagecreatetruecolor () True Color, otherwise the imagecreate () image will be distorted
- */
- The proportion of pages passed over
- $scale =$_get[' scale ');
- The following attribute is 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 in this picture, the source picture will be deleted
- $again = "Off";
- if (!empty ($_get[' again ')) {
- $again =$_get[' again '];
- }
- The first step is to create a picture based on the wide, high parameters, and then just fill the area with the intercepted part.
- 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 with the source images.
- $source = Imagecreatefromjpeg ($SRC);
- The third step, according to the parameters, select a portion of the source image to fill in the image created in the first step
- Imagecopy ($target, $source, 0, 0, $x, $y, $w, $h);
- Fourth step, Save the image
- Intercept and organize new paths
- $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, "/");
- There is temporarily no suffix ". jpg" to prevent duplicate files, if any, need to rename, add after Will inconvenient
- $newName =substr ($newName, $pos _name_-strlen ($newName) +1). " _";
- Create a picture with no suffix
- $file = $newPath. $newName;
- Append ASC Code Rename file, can also use random number, time and so on named, project requirements I don't use those naming methods.
- for ($i =0; $i <26; $i + +) {
- If the directory exists
- if (Is_dir ($newPath)) {
- If the file exists, continue looping until there are no duplicate files
- if (Is_file ($file. chr (97+ $i). ". JPG ")) {
- Continue
- }else{
- Create a file
- Imagejpeg ($target, $file. chr (97+ $i). ". JPG ", 100);
- File creation complete determines whether to delete source files, off to delete source files
- if ($again = = "Off") {
- Unlink ($SRC);
- unset ($_session[' url ');
- }
- Break
- }
- }else{
- Create a Directory
- mkdir ($newPath);
- Create a file
- Imagejpeg ($target, $file. chr (97+ $i). ". JPG ", 100);
- File creation complete determines whether to delete source files, off to delete source files
- if ($again = = "Off") {
- Unlink ($SRC);
- unset ($_session[' url ');
- }
- Break
- }
- }
- Jump to Homepage
- Header ("Location:index.php");
- ?>
Copy Code
|