"gif", 2 =>"jpg", 3 => "png", 4 => "swf"); $dOriginalWidth = $aImageInfo[0]; $dOriginalHeight = $aImageInfo[1]; $sOriginalImageType = $aTypes[$aImageInfo[2]]; //if unable to determine the type from the getimagesize function, try from the original filename if( !$sOriginalImageType && $sOriginalFilename ) { $arrNameParts = explode(".", strtolower($sOriginalFilename)); $ext = $arrNameParts[count($arrNameParts) - 1]; switch ( $ext ) { case "gif": $sOriginalImageType = "gif"; break; case "jpg": $sOriginalImageType = "jpg"; break; case "jpeg": $sOriginalImageType = "jpg"; break; case "png": $sOriginalImageType = "png"; break; } } //if unable to determine the image type, or an invalid type, fail if ( !$sOriginalImageType ) return(false); if(file_exists($sDestinationFilename.".".$sOriginalImageType)) unlink($sDestinationFilename.".".$sOriginalImageType); //if provided a new width or height, manipulate the image if( $iTargetHeight || $iTargetWidth ) { if ($sOriginalImageType == "jpg") $oOriginalImage = imagecreatefromjpeg($sSourceFilename); elseif ($sOriginalImageType == "png") $oOriginalImage = imagecreatefrompng($sSourceFilename); elseif($sOriginalImageType == "gif") $oOriginalImage = imagecreatefromgif($sSourceFilename); if($oOriginalImage) { $dAspectRatio = $dOriginalWidth/$dOriginalHeight; if($iTargetHeight && !$iTargetWidth) { $dNewHeight = $iTargetHeight; $dNewHeight = floor($dNewHeight * $dAspectRatio); } elseif($iTargetWidth && !$iTargetHeight) { $dNewHeight = $iTargetWidth; $dNewHeight = floor($dNewHeight/$dAspectRatio); } else { $dNewHeight = $iTargetHeight; $dNewHeight = $iTargetWidth; } $oNewImage = imagecreatetruecolor($dNewHeight, $dNewHeight); //copy the old image to the new image with the new dimentions imagecopyresampled($oNewImage, $oOriginalImage, 0, 0, 0, 0, $dNewHeight, $dNewHeight, $dOriginalWidth, $dOriginalHeight); if($sWatermarkImage) { //now, add the watermark $oWatermark = @imagecreatefrompng($sWatermarkImage); if($oWatermark) { $iWatermarkWidth = imagesx($oWatermark); $iWatermarkHeight = imagesy($oWatermark); $iDestinationX = $dNewHeight - $iWatermarkWidth - 5; $iDestinationY = $dNewHeight - $iWatermarkHeight - 5; imagecopymerge($oNewImage, $oWatermark, $iDestinationX, $iDestinationY, 0, 0, $iWatermarkWidth, $iWatermarkHeight, 100); } } // if this was a GIF, and GIF support is enabled, create the new file as a GIF, otherwise create a JPEG. $ok=false; if ( $sOriginalImageType == "gif" && function_exists("imagegif") ) { $sNewImageType = "gif"; $ok = imagegif($oNewImage, $sDestinationFilename.".".$sNewImageType); } if(!$ok) { $sNewImageType = "jpg"; $ok = imagejpeg($oNewImage, $sDestinationFilename.".".$sNewImageType, 100); } } } //if $ok is not set, either there was no re-sizing to be done, or it failed, so just copy the image if(!$ok) { $sNewImageType = $sOriginalImageType; $ok = copy($sSourceFilename, $sDestinationFilename.".".$sNewImageType); } if(!$ok) unset($sNewImageType); return($sNewImageType); } ?>