Skip to content

Commit

Permalink
Bugfix in cropAndScape() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Engel committed May 30, 2013
1 parent 0f934e1 commit d3b9818
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Kiss/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,14 @@ public static function dec2else($decimal, $base = 62) {
* @param {Integer} $targetHeight
* @return {String} Temporary path to the cropped and resized image
*/
public static function cropAndScale($inputImagePath, $targetWidth, $targetHeight) {
function cropAndScale($inputImagePath, $targetWidth, $targetHeight) {
$origDims = getimagesize($inputImagePath);

$sourceImage = imagecreatefromstring(file_get_contents($inputImagePath));

$targetImage = imagecreatetruecolor($targetWidth, $targetHeight);

if ($targetHeight > $targetWidth) {
if ($origDims[0] > $origDims[1]) {
//Landscape format
$srcY = 0;
$srcH = $origDims[1];
Expand All @@ -479,13 +479,13 @@ public static function cropAndScale($inputImagePath, $targetWidth, $targetHeight
else {
//Portrait or square
$srcX = 0;
$srcW = $origDims[0];
$srcH = $srcW * ($targetWidth / $targetHeight);
$srcW = min($origDims[0], $origDims[0] * ($targetWidth / $targetHeight));
$srcH = $srcW * ($targetHeight / $targetWidth);
$srcY = ($origDims[1] - $srcH) / 2;
}
imagecopyresampled($targetImage, $sourceImage, 0, 0, $srcX, $srcY, $targetWidth, $targetHeight, $srcW, $srcH);

$tmp = 'lib/people/temp.tmp'; //Whatever, doesnt work...> tempnam(sys_get_temp_dir(), 'img');
$tmp = tempnam(sys_get_temp_dir(), 'img');
imagejpeg($targetImage, $tmp, 90);
return $tmp;
}
Expand Down

0 comments on commit d3b9818

Please sign in to comment.