How does PHP do image processing? Is it possible to synthesize more than one picture? This article in PHP will be a number of pictures to synthesize a picture, so that you have a better understanding of the image processing of PHP.
1. Multiple pictures to synthesize a picture such as:
Picture compositing, can be displayed in the browser and save to the folder below
The examples are as follows:
<?php/** * Picture merge **/$pic _list = Array (' Img2.png ', ' img2.png ', ' logo.png ', ' logo.png ', ' logo.png ', ' Img2.png ', ' img2.png ', ' img2.png ', ' img2.png '); $pic _list = array_slice ($pic _list, 0, 9); Operation only the first 9 pictures $bg _w = 150; Background image width $BG _h = 150; Background image Height $background = imagecreatetruecolor ($bg _w, $BG _h); Background image $color = Imagecolorallocate ($background, 202, 201, 201); Create a white background for the true color canvas and set it to Transparent Imagefill ($background, 0, 0, $color); Imagecolortransparent ($background, $color); $pic _count = count ($pic _list); $LINEARR = Array (); Where line breaks are required $space _x = 3; $space _y = 3; $line _x = 0; Switch ($pic _count) {Case 1://Positive middle $start _x = intval ($BG _W/4);//start position x $start _y = intval ($BG _H/4);//Start position y $pic _ W = intval ($bg _w/2); Width $pic _h = intval ($bg _h/2); Height break; Case 2://middle position side-by $start _x = 2; $start _y = intval ($bg _H/4) + 3; $pic _w = intval ($BG _w/2)-5; $pic _h = intval ($BG _h/2)-5; $space _x = 5; Break Case 3: $start _x = 40; Start bitPlace x $start _y = 5; Start position y $pic _w = intval ($BG _w/2)-5; Width $pic _h = intval ($BG _h/2)-5; Height $LINEARR = array (2); $line _x = 4; Break Case 4: $start _x = 4; Start position x $start _y = 5; Start position y $pic _w = intval ($BG _w/2)-5; Width $pic _h = intval ($BG _h/2)-5; Height $LINEARR = array (3); $line _x = 4; Break Case 5: $start _x = 30; Start position x $start _y = 30; Start position y $pic _w = intval ($BG _w/3)-5; Width $pic _h = intval ($BG _h/3)-5; Height $LINEARR = array (3); $line _x = 5; Break Case 6: $start _x = 5; Start position x $start _y = 30; Start position y $pic _w = intval ($BG _w/3)-5; Width $pic _h = intval ($BG _h/3)-5; Height $LINEARR = array (4); $line _x = 5; Break Case 7: $start _x = 53; Start position x $start _y = 5; Start position y $pic _w = intval ($BG _w/3)-5; Width $pic _h = intval ($BG _h/3)-5; Height $LINEARR = array (2,5); $line _x = 5; Break Case 8: $start _x = 30; Start position x $start _y = 5; Start position y $pic _w = intval ($BG _w/3)-5; Width $pic _h = intval($BG _H/3)-5; Height $LINEARR = array (3,6); $line _x = 5; Break Case 9: $start _x = 5; Start position x $start _y = 5; Start position y $pic _w = intval ($BG _w/3)-5; Width $pic _h = intval ($BG _h/3)-5; Height $LINEARR = array (4,7); $line _x = 5; Break } foreach ($pic _list as $k = + $pic _path) {$kk = $k + 1; if (In_array ($KK, $LINEARR)) {$start _x = $line _x; $start _y = $start _y + $pic _h + $space _y; } $pathInfo = PathInfo ($pic _path); Switch (Strtolower ($pathInfo [' extension ')) {case ' jpg ': case ' jpeg ': $imagecreatefromjpeg = ' IMAGECREATEFROMJ Peg '; Break Case ' png ': $imagecreatefromjpeg = ' imagecreatefrompng '; Break Case ' GIF ': default: $imagecreatefromjpeg = ' imagecreatefromstring '; $pic _path = file_get_contents ($pic _path); Break } $resource = $imagecreatefromjpeg ($pic _path); $start _x, $start the position of the _y copy picture in the background//0,0 the position of the Copy picture//$pic _w, $pic _h the height and width after copy imagecopyresized ($background, $reso Urce, $start _x, $start_y,0,0, $pic _w, $pic _h,imagesx ($resource), Imagesy ($resource)); The last two parameters are the original width and height of the image, the image width and height when the bottom two parameters are copy $start _x = $start _x + $pic _w + $space _x; } header ("Content-type:image/jpg"); Imagejpeg ($background); Imagegif ($background, "./hero_gam.png"); ?>
Related recommendations:
Summary of common functions of PHP GD image processing components
PHP image operation class, support to generate thumbnails, add watermarks, upload thumbnails
Very strong PHP image processing class