[eluser]JoostV[/eluser]
I don't know how Facebook handles images.
But squaring here creates a square image, measured from the center of the picture. So, if an image is 200px wide and 100px high, squaring will chip 50 pixels off the left an 50 pixels off the right. Works for portrait images, too, of course
Square thumbnails squares the image first, and then resizes it to the size you specify. Say you wish to save three sizes, a thumbnail and a square thumbnail; easy as:
Code:
// Example of resizing and squaring five images in one go, using 'images' library
$sourceimagepath = '/path/to/image/folder/';
$sourceimagename = 'test.png';
$sourcefile = $sourceimagepath . $sourceimagename;
$destinationpath = '/path/to/destination/folder/';
// Store all sizes you wish to create in an array
$image_sizes[] = array('maxwidth' => 800, 'maxheight' => 800, 'subfolder' => '800', 'square' => false);
$image_sizes[] = array('maxwidth' => 450, 'maxheight' => 450, 'subfolder' => '450', 'square' => false);
$image_sizes[] = array('maxwidth' => 300, 'maxheight' => 300, 'subfolder' => '300', 'square' => false);
$image_sizes[] = array('maxwidth' => 100, 'maxheight' => 100, 'subfolder' => 'thumbs', 'square' => false);
$image_sizes[] = array('maxwidth' => 100, 'maxheight' => 100, 'subfolder' => 'thumbs_square', 'square' => true);
$this->load->library('images');
// Resize the original image and store it
foreach ($image_sizes as $image_size) {
$destinationfile = $destinationpath . $image_size['subfolder'] . '/' . $sourceimagename;
if ($image_size['square'] == false) {
$this->images->resize($sourcefile, $image_size['maxwidth'], $image_size['maxheight'], $destinationfile);
}
else {
$this->images->squareThumb($sourcefile, $destinationfile, $image_size['maxwidth']);
}
}
// You may wish to delete the original file
if (file_exists($sourcefile) && is_file($sourcefile)) {
unlink($sourcefile);
}