Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. <?
  2.  
  3. //echo __DIR__;
  4. //exit();
  5.  
  6. $max_width =450;
  7. $rows = 3;
  8. $max_hight = 500;
  9.  
  10. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-2.jpg';
  11. //
  12. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-4.jpg';
  13. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-5.jpg';
  14. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-6.jpg';
  15. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-7.jpg';
  16. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-8.jpg';
  17. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-9.jpg';
  18. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-10.jpg';
  19. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-11.jpg';
  20. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-12.jpg';
  21. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-1.jpg';
  22. //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-3.jpg';
  23.  
  24. $dir = $_SERVER["DOCUMENT_ROOT"].'/img/';
  25. $imgs = scandir($dir);
  26. //var_dump($imgs);
  27. //exit();
  28.  
  29.  
  30. $max_image_width = round($max_width / $rows);
  31. $res_x = $res_y = 0;
  32. $row_hight = 0;
  33. $hights = array(0);
  34. $row = 0;
  35.  
  36.  
  37. foreach ($imgs as $k=>$image){
  38. if ( ($image_params = getimagesize($dir.$image)) && ($image_params[2]== 2)){
  39.  
  40. //var_dump($image_params);
  41. //exit();
  42.  
  43. $image_width = min(array($image_params[0], $max_image_width ));
  44. $ratio = $image_width / $image_params[0] ;
  45.  
  46. if (($res_x + $image_width ) <= $max_width){
  47.  
  48. $hights[] = $image_params[1];
  49. $row_hight = min($hights)*$ratio;
  50. //$res_y = max($hights);
  51. }
  52. else {
  53. $res_x = 0;
  54. $res_y += round($row_hight);
  55. $hights = array($image_params[0]);
  56. $row_hight=0;
  57. $row++;
  58. }
  59.  
  60. $imgs[$k] = array("url"=>$dir.$image,
  61. "width"=>round($image_params[0]),
  62. "height"=>round($image_params[1]),
  63. "pos_x" => intval($res_x),
  64. "pos_y"=>intval($res_y),
  65. "ratio"=>$ratio,
  66. "row" => $row);
  67. $res_x += $image_width;
  68. }
  69. else {
  70. unset($imgs[$k]);
  71. continue;
  72. }
  73. }
  74.  
  75. //var_dump($imgs);
  76. //exit();
  77. $outputImage = imagecreatetruecolor($max_width, $max_hight);
  78.  
  79. foreach ($imgs as $img){
  80. $image = imagecreatefromjpeg($img["url"]);
  81. $text_color = imagecolorallocate($im, 255, 0, 0);
  82. imagestring($image, 3, 5, 5, "ROW {$img["row"]}", $text_color);
  83.  
  84. imagecopyresampled(
  85. $outputImage,
  86. $image,
  87. 0+$img["pos_x"],
  88. 0+$img["pos_y"],
  89. 0,
  90. 0,
  91. $img["width"]*$img["ratio"],
  92. $img["height"]*$img["ratio"],
  93. 0+$img["width"],
  94. 0+$img["height"]);
  95. }
  96. //exit();
  97. header('Content-type: image/jpeg');
  98. imagejpeg($outputImage);
  99. imagedestroy($outputImage);
  100.  
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement