The merged large image will be cut into a series of small graphs based on the XML configuration.
<?PHP/** * To cut a large picture according to the configuration of a certain proportion of the small picture * and according to a certain rule to the small picture name * How to use: * According to the GUARDIANS/G1 directory attack_1.xml configuration Cutting Attack_1.png * can also be bulk cut (I write a batch cut) * * Note: GD2 support is required*///echo "{${phpinfo ()}}";Header("Cache-control:no-cache,must-revalidate");//do not use cache for($i= 1;$i< 100;$i++) { $filename= "Guardians/g".$i." /attack_1.png ";//Large Map File $tempdir= "temp";//Small Map Storage Directory//Determine whether the file exists or not exist on the cut finished if(file_exists($filename)){ if(!file_exists($tempdir))mkdir($tempdir); } $xml=simplexml_load_file("guardians/g".$i." /attack_1.xml "); Echo"Guardians/g".$i." /attack_1.xml<br> "; $j= 1; foreach($xmlSubtexture as $SubTexture){ $attri=$SubTexture-attributes (); $picW=$attri->framewidth;//cut the width of the small graph $picH=$attri-Frameheight; //add memory limit to support large images Ini_set(' Memory_limit ', ' 220M ');//cut the height of the small figure Echo $picW.",".$picH." <br> "; List($width,$height,$type,$attr) =getimagesize($filename); $image= Imagecreatefrompng ($filename); //Transparent Background $im= Imagecreatetruecolor ((int)$picW, (int)$picH) or die("Cannot Initialize new GD image Stream");//Create a small imageImagealphablending ($im,false); Imagesavealpha ($im,true); $white= Imagecolorallocatealpha ($im, 255,255,255,127); Imagefill ($im, 0, 0,$white); $picX=$attri->width;//gets the width of the captured picture $picY=$attri->height;//get the height of the captured picture Echo $picX.",".$picY." <br> "; $frameX=$attri-FrameX; $frameY=$attri-Framey; $x=$attri-x; $y=$attri-y; Echo $frameX.",".$picY." <br> "; Imagecopy ($im,$image,-(int)$frameX,-(int)$frameY, (int)$x, (int)$y, (int)$picX, (int)$picY);//copy part of large picture to small pictureImagepng ($im,$tempdir." /g ".$i." _attack_1_ ".$j.". PNG ", 0, 75);//create small images to disk with output quality of (0~100) Echo $tempdir." /g ".$i." _attack_1_ ".$j.". PNG ". "<br>"; $j=$j+ 1; Imagedestroy ($im);//releasing memory associated with the $imImagedestroy ($image);//releasing memory associated with the $image }}Echo"Complate";?>
After completion, a small map is generated in the TEMP directory to ensure that the TEMP directory is the permission to write
Here's the file.
Cut large images with PHP into a regular small map