Thumbnail images to same size collage making

dear programmers i need small customization like i have some images in images folder with size 200x200. now i need to create collage from them with size defined of perticular image as 50x50 to resize them and fit them in predefined canvas like 500x500 or else. in jpeg format.
[][][][]
[][][][]
[][][][]
so that it wood be like above you can check below link also for reference
[https://i.imgur.com/rRPN65E.jpg](http://image sample)

So what’s the problem, you didn’t ask any question, nor provided any faulty code. Just do it, start here:

https://www.php.net/manual/en/function.imagecopyresized.php

I tried this

<?php
// Get list of all JPG files in a particular path
$files = glob('/path/to/my/folder/*.jpg');
// Create a canvas for the collage
$canvas = imagecreate(500, 500);
// Hold a row counter
$row=0;
// Start iterating over files that will make up the collage
for ($i=0; $i<count($files); $i++) {
    // If $i isn't 0, and is divisible by 10, increment the row counter
    if ($i>0 && $i%10 == 0) { $row++; }
    $original = imagecreatefromjpeg($files[$i]);
        
    // Option A: Scale image yourself first and add to collage
    $scaled = imagescale($original, 50, 50);
    imagecopymerge($canvas, $scaled, 50*$i, 50*$row, 0, 0, 50, 50, 100);
    
    // Option B: Copy and scale at the same time
    list($width, $height) = getimagesize($files[$i]);
    imagecopyresampled($canvas, $original, 50*$i, 50*$row, 0, 0, 50, 50, $width, $height);
    
    // Free up memory
    imagedestroy($original);
}
// output the image
header('Content-Type: image/jpeg');
imagejpeg($canvas);
// Free up memory
imagedestroy($canvas);

But
its only showing 10 images in first row and other rows are blank… can you please move a little bit more… thanks. also images are showing in some unknown color :grinning: like below image
Imgur

That’s unreadable. At least you can use the button in the editor </> to insert code.

	   <?php 
	    // Get list of all JPG files in a particular path 
	    $files = glob('/path/to/my/folder/*.jpg'); 

	// Create a canvas for the collage 
	$canvas = imagecreate(500, 500); 

	// Hold a row counter $row=0; 
	// Start iterating over files that will make up the collage 
	for ($i=0; $i0 && $i%10 == 0) 
	{ 
		$row++; 
	} 
	$original = imagecreatefromjpeg($files[$i]); 

	// Option A: Scale image yourself first and add to collage 
	$scaled = imagescale($original, 50, 50); 

	imagecopymerge($canvas, $scaled, 50*$i, 50*$row, 0, 0, 50, 50, 100); 

	// Option B: Copy and scale at the same time 

	list($width, $height) = getimagesize($files[$i]); 

	imagecopyresampled($canvas, $original, 50*$i, 50*$row, 0, 0, 50, 50, $width, $height); 

	// Free up memory imagedestroy($original); } 
	// output the image header('Content-Type: image/jpeg');
	imagejpeg($canvas);
	// Free up memory imagedestroy($canvas); 
	?>

But I am not sure whether the above code will work or not…

its not working dear and for loop is also wrong…

Sponsor our Newsletter | Privacy Policy | Terms of Service