Hey,
Im using interakts Kollection to put a site together and would like help editing one of the functions to actually crop the thumbs that are created.
This is the code on the page where the variables are taken from. This code wouldnt need changing... just something in the big chunk to actually do the cropping.
// Show Dynamic Thumbnail
$objDynamicThumb1 = new tNG_DynamicThumbnail("../", "KT_thumbnail1");
$objDynamicThumb1->setFolder("../member_img/");
$objDynamicThumb1->setRenameRule("{photos.g_img}");
$objDynamicThumb1->setResize(120, 120, false);
$objDynamicThumb1->setWatermark(false);
if ($this->getFileName() !== false) {
// make the resize
$proportional = $this->keepProportion;
$width = $this->width;
$height = $this->height;
if (!$this->watermark) {
$thumbnailName = $path_info['filename'].'_'.$width.'x'.$height.(isset($path_info['extension'])?'.'.$path_info['extension']:'');
} else {
$hash = tNG_watermarkHash(KT_realpath($this->watermarkImage, false), $this->watermarkAlpha, $this->watermarkResize, $this->watermarkAlignment);
$thumbnailName = $path_info['filename'].'_'.$width.'x'.$height.'_w_'.$hash.(isset($path_info['extension'])?'.'.$path_info['extension']:'');
}
$thumbnailFullName = $thumbnailFolder . $thumbnailName;
if (!file_exists(KT_realpath($thumbnailFullName, false)) ) {
$imageObj = new KT_image();
$imageObj->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
$imageObj->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
$imageObj->thumbnail($fullFileName, $thumbnailFolder, $thumbnailName, (int)$width, (int)$height, $proportional);
if ($imageObj->hasError()) {
$errorArr = $imageObj->getError();
if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
$errMsg = $errorArr[1];
$ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />".$errMsg."<img style=\"display:none\" src=\"".$relpath."includes/tng/styles/cannot_thumbnail.gif";
} else {
$ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif";
}
return $ret;
} else {
// apply watermark
if ($this->watermark) {
// delete other watermarks for same picture
tNG_deleteThumbnails($thumbnailFolder, $path_info['filename'].'_'.$width.'x'.$height, $hash);
$imageObj = new KT_image();
$imageObj->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
$imageObj->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
$imageObj->watermark($thumbnailFullName, $thumbnailFullName, KT_realpath($this->watermarkImage, false), $this->watermarkAlpha, $this->watermarkResize, $this->watermarkAlignment);
if ($imageObj->hasError()) {
@unlink($thumbnailFullName);
$arrError = $imageObj->getError();
$errObj = new tNG_error('IMG_WATERMARK', array(), array($arrError[1]));
if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
$errMsg = $arrError[1];
$ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />".$errMsg."<img style=\"display:none\" src=\"".$relpath."includes/tng/styles/cannot_thumbnail.gif";
} else {
$ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif";
}
return $ret;
}
}
}
$ret = $relpath . substr($thumbnailFullName, strlen(KT_realpath($relpath)));
if (!$imageObj->hasError()) {
//$ret .= '?' . md5(filectime($ret));
}
} else {
$ret = $relpath . substr($thumbnailFullName, strlen(KT_realpath($relpath)));
//$ret .= '?' . md5(filectime($ret));
}
} else {
$ret = $relpath . "includes/tng/styles/img_not_found.gif";
}
}
return $ret;
}
}
Thanks in advance to anyone who can help out!
Danny
Ps.... This is the crop code i had been using. But i want to try and get it into the function somehow so that i can crop all thumbs without having to add this extra code:
$imgSrc = "../member_img/dan_lewin_9.jpg";
//getting the image dimensions
list($width, $height) = getimagesize($imgSrc);
//saving the image into memory (for manipulation with GD Library)
$myImage = imagecreatefromjpeg($imgSrc);
///--------------------------------------------------------
//setting the crop size
//--------------------------------------------------------
if($width > $height){
$biggestSide = $width;
$cropPercent = .6;
$cropWidth = $biggestSide*$cropPercent;
$cropHeight = $biggestSide*$cropPercent;
$c1 = array("x"=>($width-$cropWidth)/2, "y"=>($height-$cropHeight)/2);
}else{
$biggestSide = $height;
$cropPercent = .6;
$cropWidth = $biggestSide*$cropPercent;
$cropHeight = $biggestSide*$cropPercent;
$c1 = array("x"=>($width-$cropWidth)/2, "y"=>($height-$cropHeight)/7);
}
//--------------------------------------------------------
// Creating the thumbnail
//--------------------------------------------------------
$thumb1 = imagecreatetruecolor(60,60);
imagecopyresampled($thumb1, $myImage, 0, 0, $c1['x'], $c1['y'], 60, 60, $cropWidth, $cropHeight);
$thumb2 = imagecreatetruecolor(120,120);
imagecopyresampled($thumb2, $myImage, 0, 0, $c1['x'], $c1['y'], 120, 120, $cropWidth, $cropHeight);
//final output
imagejpeg($thumb1, "../member_img/thumbnails/dan_lewin_9_60x60.jpg", 100);
imagejpeg($thumb2, "../member_img/thumbnails/dan_lewin_9_120x120.jpg", 100);
imagedestroy($thumb1);
imagedestroy($thumb2);