Skip to content

Instantly share code, notes, and snippets.

View roosmaa's full-sized avatar

Mart Roosmaa roosmaa

  • Spain
View GitHub Profile
@roosmaa
roosmaa / boxed_thumbnail.php
Created August 11, 2010 14:28
Resizes a picture to fit in a box, clipping the edges if necessary. When picture smaller than the given box, centers the picture and adds a transparent background.
<?php function boxed_thumbnail($data, $size)
{
$src = imagecreatefromstring($data);
$src_width = imagesx($src);
$src_height = imagesy($src);
// Resize algo:
$src_ratio = $src_width / $src_height;
$trg_ratio = $size[0] / $size[1];