'application', 'jpeg'=>'image', 'png'=>'image', 'gif'=>'image'); if($sType!='html' && array_key_exists($sType, $asMainTypes)) header('Content-type: '.$asMainTypes[$sType].'/'.$sType); } function getTrimImage($iFilmId, $sinPath, $sImageExt) { $sOutPath = 'images/'.$iFilmId.'.'.$sImageExt; if(!file_exists($sOutPath)) { $oImage = call_user_func('imagecreatefrom'.$sImageExt, $sinPath); $iImageX = imagesx($oImage); $iImageY = imagesy($oImage); $iTop = 0; $iBottom = 0; $iLeft = 0; $iRight = 0; $iWhiteLimit = 220; //Top height to crop: for(; $iTop < $iImageY; ++$iTop) { for($x = 0; $x < $iImageX; ++$x) { $hColor = imagecolorat($oImage, $x, $iTop); $iRed = ($hColor >> 16) & 0xFF; $iGreen = ($hColor >> 8) & 0xFF; $iBlue = $hColor & 0xFF; if($iRed<$iWhiteLimit || $iGreen<$iWhiteLimit || $iBlue<$iWhiteLimit) break 2; //out of the 'top' loop } } //Bottom height to crop for(; $iBottom < $iImageY; ++$iBottom) { for($x = 0; $x < $iImageX; ++$x) { $hColor = imagecolorat($oImage, $x, $iImageY - $iBottom - 1); $iRed = ($hColor >> 16) & 0xFF; $iGreen = ($hColor >> 8) & 0xFF; $iBlue = $hColor & 0xFF; if($iRed<$iWhiteLimit || $iGreen<$iWhiteLimit || $iBlue<$iWhiteLimit) break 2; //out of the 'bottom' loop } } //Left width to crop for(; $iLeft < $iImageX; ++$iLeft) { for($y = 0; $y < $iImageY; ++$y) { $hColor = imagecolorat($oImage, $iLeft, $y); $iRed = ($hColor >> 16) & 0xFF; $iGreen = ($hColor >> 8) & 0xFF; $iBlue = $hColor & 0xFF; if($iRed<$iWhiteLimit || $iGreen<$iWhiteLimit || $iBlue<$iWhiteLimit) break 2; //out of the 'left' loop } } //Right width to crop for(; $iRight < $iImageX; ++$iRight) { for($y = 0; $y < $iImageY; ++$y) { $hColor = imagecolorat($oImage, $iImageX - $iRight-1, $y); $iRed = ($hColor >> 16) & 0xFF; $iGreen = ($hColor >> 8) & 0xFF; $iBlue = $hColor & 0xFF; if($iRed<$iWhiteLimit || $iGreen<$iWhiteLimit || $iBlue<$iWhiteLimit) break 2; //out of the 'right' loop } } //Creating a image with the new height $oCropImage = imagecreatetruecolor($iImageX-($iLeft+$iRight), $iImageY-($iTop+$iBottom)); //Copy the content, excluding the border imagecopy($oCropImage, $oImage, 0, 0, $iLeft, $iTop, imagesx($oCropImage), imagesy($oCropImage)); call_user_func_array('image'.$sImageExt, array($oCropImage, $sOutPath)); } return file_get_contents($sOutPath); } ?>