diff --git a/images/logo_ugc.png b/images/logo_ugc.png new file mode 100755 index 0000000..2eda1ae Binary files /dev/null and b/images/logo_ugc.png differ diff --git a/inc/functions.php b/inc/functions.php index f9806d5..28e6160 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -25,7 +25,86 @@ function getPage($sPath, $asVars, $bSavePage=false) function setPageMime($sType='html') { - if($sType!='html') header('Content-type: application/'.$sType); + $asMainTypes = array('json'=>'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); } ?> \ No newline at end of file diff --git a/index.php b/index.php index c283a92..72f3ff1 100755 --- a/index.php +++ b/index.php @@ -1,5 +1,8 @@ - @@ -15,7 +14,7 @@
-