Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- //echo __DIR__;
- //exit();
- $max_width =450;
- $rows = 3;
- $max_hight = 500;
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-2.jpg';
- //
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-4.jpg';
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-5.jpg';
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-6.jpg';
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-7.jpg';
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-8.jpg';
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-9.jpg';
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-10.jpg';
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-11.jpg';
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-12.jpg';
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-1.jpg';
- //$imgs[] = $_SERVER["DOCUMENT_ROOT"].'/img/foto-3.jpg';
- $dir = $_SERVER["DOCUMENT_ROOT"].'/img/';
- $imgs = scandir($dir);
- //var_dump($imgs);
- //exit();
- $max_image_width = round($max_width / $rows);
- $res_x = $res_y = 0;
- $row_hight = 0;
- $hights = array(0);
- $row = 0;
- foreach ($imgs as $k=>$image){
- if ( ($image_params = getimagesize($dir.$image)) && ($image_params[2]== 2)){
- //var_dump($image_params);
- //exit();
- $image_width = min(array($image_params[0], $max_image_width ));
- $ratio = $image_width / $image_params[0] ;
- if (($res_x + $image_width ) <= $max_width){
- $hights[] = $image_params[1];
- $row_hight = min($hights)*$ratio;
- //$res_y = max($hights);
- }
- else {
- $res_x = 0;
- $res_y += round($row_hight);
- $hights = array($image_params[0]);
- $row_hight=0;
- $row++;
- }
- $imgs[$k] = array("url"=>$dir.$image,
- "width"=>round($image_params[0]),
- "height"=>round($image_params[1]),
- "pos_x" => intval($res_x),
- "pos_y"=>intval($res_y),
- "ratio"=>$ratio,
- "row" => $row);
- $res_x += $image_width;
- }
- else {
- unset($imgs[$k]);
- continue;
- }
- }
- //var_dump($imgs);
- //exit();
- $outputImage = imagecreatetruecolor($max_width, $max_hight);
- foreach ($imgs as $img){
- $image = imagecreatefromjpeg($img["url"]);
- $text_color = imagecolorallocate($im, 255, 0, 0);
- imagestring($image, 3, 5, 5, "ROW {$img["row"]}", $text_color);
- imagecopyresampled(
- $outputImage,
- $image,
- 0+$img["pos_x"],
- 0+$img["pos_y"],
- 0,
- 0,
- $img["width"]*$img["ratio"],
- $img["height"]*$img["ratio"],
- 0+$img["width"],
- 0+$img["height"]);
- }
- //exit();
- header('Content-type: image/jpeg');
- imagejpeg($outputImage);
- imagedestroy($outputImage);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement