Пример #1
0
 function CreateResizedCopy($strSourceFile, $strTargetPath, $strTargetName, $intWidth, $intHeight, $intSourceWidth = 0, $intSourceHeight = 0)
 {
     // check dimensions
     if (empty($intSourceWidth) || empty($intSourceHeight)) {
         $size = @getimagesize($strSourceFile);
         if (empty($size)) {
             $this->errMsg = 'Erreur : ne peut obtenir la taille du fichier ' . $strTargetPath . '<br>';
             return false;
         }
         $intSourceWidth = $size[0];
         $intSourceHeight = $size[1];
     }
     $ratio = 1;
     if ($intSourceWidth > $intWidth || $intSourceHeight > $intHeight) {
         $ratio = $intHeight / $intSourceHeight < $intWidth / $intSourceWidth ? $intHeight / $intSourceHeight : $intWidth / $intSourceWidth;
     }
     $ext = HelperAlbum::GetExtension($strTargetName);
     if ($ext == "jpg" || $ext == "jpeg") {
         $imageSource = @imagecreatefromjpeg($strSourceFile);
         $targetImage = @imagecreatetruecolor(round($intSourceWidth * $ratio), round($intSourceHeight * $ratio));
         @imagecopyresized($targetImage, $imageSource, 0, 0, 0, 0, round($intSourceWidth * $ratio), round($intSourceHeight * $ratio), $intSourceWidth, $intSourceHeight);
         if (!imagejpeg($targetImage, $strTargetPath . $strTargetName)) {
             $this->errMsg = 'Erreur : ne peux créer l\'image pour ' . $strTargetPath . '<br>';
         }
     }
     if ($ext == "png") {
         $imageSource = @imagecreatefrompng($strSourceFile);
         $targetImage = @imagecreatetruecolor(round($intSourceWidth * $ratio), round($intSourceHeight * $ratio));
         imagealphablending($targetImage, false);
         $colorTransparent = imagecolorallocatealpha($targetImage, 0, 0, 0, 127);
         imagefill($targetImage, 0, 0, $colorTransparent);
         imagesavealpha($targetImage, true);
         @imagecopyresized($targetImage, $imageSource, 0, 0, 0, 0, round($intSourceWidth * $ratio), round($intSourceHeight * $ratio), $intSourceWidth, $intSourceHeight);
         if (!imagepng($targetImage, $strTargetPath . $strTargetName)) {
             $this->errMsg = 'Erreur : ne peux créer l\'image pour ' . $strTargetPath . '<br>';
         }
     }
     return true;
 }
Пример #2
0
 function IsPicture($file)
 {
     $ext = HelperAlbum::GetExtension($file['name']);
     $max_size = 3000000;
     if (!($ext == "jpg" || $ext == "jpeg" || $ext == "png")) {
         $this->errMsg = "L'image/photo doit être une *.jpg - *.jpeg - *.png";
         return false;
     }
     if ($file['size'] >= $max_size || $file['size'] == 0) {
         $this->errMsg = "Erreur : La taille d'image/photo doit être < 3Mo.<br>";
         return false;
     }
     return in_array($ext, $this->extensions);
 }