(time() - (REFRESH_DELAY * 3600))) { displayImage($tRealPathFile); exit; } if (array_key_exists('mime', $aFileInfo)) { $oImageOriginal = null; $aFileType = array( 'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif'), 'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', 'imageJpegV2'), 'image/png' => array( 'imagecreatefrompng', 'bits', 'imagepng'), 'image/vnd.wap.wmbp' => array( 'imagecreatefromwbmp', 'palette', 'imagewbmp'), ); if (!isset($aFileType[($aFileInfo['mime'])])) { displayError(); } list ($sImageLoader, $sColorStyle, $sSaveType) = $aFileType[($aFileInfo['mime'])]; if ($sColorStyle == 'palette') { $bTrueColor = false; } elseif ($sColorStyle == 'truecolor') { $bTrueColor = true; } elseif ($sColorStyle == 'bits') { $bTrueColor = ($aFileInfo['bits'] >= 8); } if ($nWidth > 0 && $nHeight == 0) { if ($aFileInfo[0] > $nWidth) { $nNewWidth = $nWidth; $nNewHeight = round($aFileInfo[1] * $nNewWidth / $aFileInfo[0]); } else { $nNewWidth = $aFileInfo[0]; $nNewHeight = $aFileInfo[1]; } } elseif ($nWidth == 0 && $nHeight > 0) { if ($aFileInfo[1] > $nHeight) { $nNewHeight = $nHeight; $nNewWidth = round($aFileInfo[0] * $nNewHeight / $aFileInfo[1]); } else { $nNewHeight = $aFileInfo[1]; $nNewWidth = $aFileInfo[0]; } } elseif ($nWidth > 0 && $nHeight > 0) { if ($aFileInfo[0] > $aFileInfo[1]) { $nNewWidth = $nWidth; $nNewHeight = round($aFileInfo[1] * $nNewWidth / $aFileInfo[0]); } elseif ($aFileInfo[1] > $aFileInfo[0]) { $nNewHeight = $nHeight; $nNewWidth = round($aFileInfo[0] * $nNewHeight / $aFileInfo[1]); } else { $nNewWidth = $nNewHeight = min($nWidth, $nHeight); } if ($nNewWidth > $nWidth) { $nNewWidth = $nWidth; $nNewHeight = round($aFileInfo[1] * $nNewWidth / $aFileInfo[0]); } if ($nNewHeight > $nHeight) { $nNewHeight = $nHeight; $nNewWidth = round($aFileInfo[0] * $nNewHeight / $aFileInfo[1]); } } $oImageOriginal = call_user_func($sImageLoader, $sPathFile); if ($bTrueColor) { $oNewImage = imagecreatetruecolor($nNewWidth, $nNewHeight); } else { $oNewImage = imagecreate($nNewWidth, $nNewHeight); } imagecopyresampled($oNewImage, $oImageOriginal, 0, 0, 0, 0, $nNewWidth, $nNewHeight, $aFileInfo[0], $aFileInfo[1]); imagedestroy($oImageOriginal); if (!is_dir($sPathDestination)) { mkdir($sPathDestination, 0750, true); } $sFolder = $sPathDestination.'/'.$nWidth.'x'.$nHeight."/".substr($sFile, 0, strrpos($sFile, '/')); if (!file_exists($sFolder)) { mkdir($sFolder, 0750, true); } $sNewPathFile = $sPathDestination.'/'.$nWidth.'x'.$nHeight."/".$sFile; call_user_func($sSaveType, $oNewImage, $sNewPathFile); imagedestroy($oNewImage); } displayImage($tRealPathFile); exit; ?>