/*** Goofy 2011-11-29 * Image Processing: based on the passed coordinate parameters, x, y, w, and h are the selected x coordinates, y coordinates, w width, h height * use the imagecopy () method to copy the area to the blank image created in step 1 * Note that the image must be in the true color of imagecreatetruecolor () when being created, otherwise use imagecreate () the image will be distorted */
-
- /**
- * Goofy 2011-11-29
- * Image Processing: the x, y, w, h coordinates, w width, and h are selected based on the passed coordinate parameters.
- * Use the imagecopy () method to copy the area to the blank image created in step 1.
- * Note: You must use the true color of imagecreatetruecolor () when creating an image. Otherwise, the image with imagecreate () will be distorted.
- */
- // Proportion of the page passed in
- $ Scale = $ _ GET ['scale'];
- // Multiply the following attributes by the corresponding proportions
- $ X = $ _ GET ['x'] * $ scale;
- $ Y = $ _ GET ['Y'] * $ scale;
- $ W = $ _ GET ['w'] * $ scale;
- $ H = $ _ GET ['H'] * $ scale;
- // Source path
- $ Src = $ _ GET ['src'];
- // Continue? If the source image is not deleted
- $ Again = "off ";
- If (! Empty ($ _ GET ['again ']) {
- $ Again = $ _ GET ['again '];
- }
- // The first step is to create an image based on the incoming width and high parameters, and then fill the captured part in this area.
- Header ("Content-type: image/jpeg ");
- $ Target = @ imagecreatetruecolor ($ w, $ h)
- Or die ("Cannot Initialize new GD image stream ");
- // Step 2: obtain the source image based on the path and create an image object with the source image
- $ Source = imagecreatefromjpeg ($ src );
- // Step 3: fill in part of the source image to the image created in step 1 based on the sent parameters
- Imagecopy ($ target, $ source, 0, 0, $ x, $ y, $ w, $ h );
- // Step 4: save the image
- // Truncate and organize a new path
- $ Pos_path = strripos ($ src ,"/");
- $ NewPath = substr ($ src, 0, $ pos_path-strlen ($ src). "_ new /";
- // Truncate and organize a new name
- $ Pos_name = strripos ($ src ,".");
- $ NewName = substr ($ src, 0, $ pos_name );
- $ Pos_name _ = strripos ($ newName ,"/");
- // Do not include the suffix ". jpg" to prevent duplicate files. If yes, you need to rename the files. it will be inconvenient to add them.
- $ NewName = substr ($ newName, $ pos_name _-strlen ($ newName) + 1 )."_";
- // Generate an image without a suffix
- $ File = $ newPath. $ newName;
- // Append the asc code to rename the file. you can also use a random number or time to name the file. I don't need to use the naming methods for the project.
- For ($ I = 0; $ I <26; $ I ++ ){
- // If the directory exists
- If (is_dir ($ newPath )){
- // If the file exists, continue the loop until the file with no duplicate names exists
- If (is_file ($ file. chr (97 + $ I). ". jpg ")){
- Continue;
- } Else {
- // Create a file
- Imagejpeg ($ target, $ file. chr (97 + $ I). ". jpg", 100 );
- // After the file is created, determine whether to delete the source file. off is the source file to be deleted.
- 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 );
- // After the file is created, determine whether to delete the source file. off is the source file to be deleted.
- If ($ again = "off "){
- Unlink ($ src );
- Unset ($ _ SESSION ['URL']);
- }
- Break;
- }
- }
- // Jump to the homepage
- Header ("Location: index. php ");
- ?>
|