• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Added to Wiki: image resizing and squaring library

#4
[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 Smile

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);
}


Messages In This Thread
Added to Wiki: image resizing and squaring library - by El Forum - 12-07-2009, 05:29 AM
Added to Wiki: image resizing and squaring library - by El Forum - 02-03-2010, 03:16 PM
Added to Wiki: image resizing and squaring library - by El Forum - 02-04-2010, 05:12 AM
Added to Wiki: image resizing and squaring library - by El Forum - 02-04-2010, 07:29 AM
Added to Wiki: image resizing and squaring library - by El Forum - 06-07-2010, 03:02 AM
Added to Wiki: image resizing and squaring library - by El Forum - 06-07-2010, 03:46 AM
Added to Wiki: image resizing and squaring library - by El Forum - 06-07-2010, 05:08 AM
Added to Wiki: image resizing and squaring library - by El Forum - 06-08-2010, 02:22 AM
Added to Wiki: image resizing and squaring library - by El Forum - 06-08-2010, 09:37 AM
Added to Wiki: image resizing and squaring library - by El Forum - 06-08-2010, 10:06 AM
Added to Wiki: image resizing and squaring library - by El Forum - 04-21-2011, 05:55 AM
Added to Wiki: image resizing and squaring library - by El Forum - 04-27-2011, 05:04 AM
Added to Wiki: image resizing and squaring library - by El Forum - 04-27-2011, 05:11 AM
Added to Wiki: image resizing and squaring library - by El Forum - 04-27-2011, 05:40 AM
Added to Wiki: image resizing and squaring library - by El Forum - 04-27-2011, 06:29 AM
Added to Wiki: image resizing and squaring library - by El Forum - 04-28-2011, 06:36 AM
Added to Wiki: image resizing and squaring library - by El Forum - 06-24-2011, 01:14 AM
Added to Wiki: image resizing and squaring library - by El Forum - 06-24-2011, 01:27 AM
Added to Wiki: image resizing and squaring library - by El Forum - 07-18-2011, 11:32 AM
Added to Wiki: image resizing and squaring library - by El Forum - 05-06-2012, 01:14 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.