Example #1
17
 /**
  * Método para manipulação da foto do perfil
  * Este método utiliza uma classe externa que não foi criada por mim
  */
 public function uploadFoto()
 {
     if (Input::exists('files')) {
         $fotoperfil = isset($_FILES[$this->coluna]) ? $_FILES[$this->coluna] : null;
         if ($fotoperfil['error'] > 0) {
             echo 'Nenhuma imagem enviada.<br>';
         } else {
             // array com extensões válidas
             $validExtensions = array('.jpg', '.jpeg');
             // pega a extensão do arquivo enviado
             $fileExtension = strrchr($fotoperfil['name'], ".");
             // testa se extensão é permitida
             if (in_array($fileExtension, $validExtensions)) {
                 $manipulator = new ImageManipulator($fotoperfil['tmp_name']);
                 // o tamanho da imagem poderia ser 800x600
                 $width = $manipulator->getWidth();
                 $height = $manipulator->getHeight();
                 // Encontrando o centro da imagem
                 $centreX = round($width / 2);
                 // 400
                 $centreY = round($height / 2);
                 //300
                 // Define canto esquerdo de cima
                 if ($width > $height) {
                     // Parâmetros caso a imagem fornecida seja no formato paisagem
                     $x1 = $centreX - $centreY;
                     // 400 - 300 = 100 "Topo esquerdo X"
                     $y1 = 0;
                     // "Topo esquerdo Y"
                     // Define canto direito de baixo
                     $x2 = $centreX + $centreY;
                     // 400 + 300 = 700 / 2 "Base X"
                     $y2 = $centreY * 2;
                     // 300 * 2 = 600 "Base Y"
                 } else {
                     // Parâmetros caso a imagem não seja no formato paisagem
                     $y1 = $centreY - $centreX;
                     // 400 - 300 = 100 "Topo esquerdo X"
                     $x1 = 0;
                     // "Topo esquerdo Y"
                     // Define canto direito de baixo
                     $y2 = $centreX + $centreY;
                     // 400 + 300 = 700 / 2 "Base X"
                     $x2 = $centreX * 2;
                     // 300 * 2 = 600 "Base Y"
                 }
                 // corta no centro  200x200
                 $manipulator->crop($x1, $y1, $x2, $y2);
                 // redimensiona a imagem para 400x400
                 $manipulator->resample(400, 400, true);
                 $manipulator->save(IMG_UPLOADS_FOLDER . $this->arquivo_temp);
                 $this->foto_enviada = true;
             } else {
                 $this->foto_enviada = false;
             }
         }
     }
 }
Example #2
0
 public function resize(ImageManipulator $image, $newPath, $newWidth, $newHeight)
 {
     $path = $image->getImagePath();
     $height = $image->getHeight();
     $width = $image->getWidth();
     $this->setMemoryForImage($path);
     $newimg = $this->getGDImage($path);
     if ($newimg) {
         // resize large images in two steps - first resample, then resize
         // http://lt.php.net/manual/en/function.imagecopyresampled.php
         if (($width > 1500 || $height > 1200) && ($newWidth < 1024 && $newHeight < 768)) {
             list($width, $height) = $this->resample($newimg, $image, $width, $height, 1024, 768, 0);
         }
         $resized = $this->resample($newimg, $image, $width, $height, $newWidth, $newHeight);
         if (!is_dir(dirname($newPath))) {
             mkdir(dirname($newPath), 0777, true);
         }
         // simply copy images that do not need to be resized
         if (!$resized) {
             copy($path, $newPath);
             return true;
         }
         $this->save($image->getType(), $newimg, $newPath, $image->getQuality());
         imagedestroy($newimg);
         return true;
     } else {
         return false;
     }
 }
Example #3
0
 $licenseissuedateid6 = mysqli_real_escape_string($db, $_POST["licenseissuedateid6"]);
 $licenseissuedateid6 = encrypt($licenseissuedateid6, "");
 $licenseexpirationdateid6 = mysqli_real_escape_string($db, $_POST["licenseexpirationdateid6"]);
 $licenseexpirationdateid6 = encrypt($licenseexpirationdateid6, "");
 $licensetermid6 = mysqli_real_escape_string($db, $_POST["licensetermid6"]);
 $licensetermid6 = encrypt($licensetermid6, "");
 //Process New Profile Picture
 if ($_FILES['picture']['name']) {
     require_once "ImageManipulator.php";
     $validExtensions = array('.jpg', '.JPG', '.jpeg', '.JPEG', '.gif', '.GIF', '.png', '.PNG');
     $fileExtension = strrchr($_FILES['picture']['name'], ".");
     if (in_array($fileExtension, $validExtensions)) {
         $newNamePrefix = time() . '_';
         $manipulator = new ImageManipulator($_FILES['picture']['tmp_name']);
         $manipulator->resample(500, 500);
         $width = $manipulator->getWidth();
         $height = $manipulator->getHeight();
         $centreX = round($width / 2);
         $centreY = round($height / 2);
         $x1 = $centreX - 150;
         $y1 = $centreY - 150;
         $x2 = $centreX + 150;
         $y2 = $centreY + 150;
         $newImage = $manipulator->crop($x1, $y1, $x2, $y2);
         // saving file to uploads folder
         $picturefilename = $newNamePrefix . $_FILES['picture']['name'];
         $manipulator->save($portal_path_root . '/../private/directory/images/employees/' . $picturefilename);
     }
 } else {
     $picturefilename = $currentpicture;
 }
 public function createThumbnail()
 {
     $im = new ImageManipulator($this->pathProfilePic . $this->get('profilepic'));
     $centerX = round($im->getWidth() / 2);
     $centerY = round($im->getHeight() / 2);
     if ($im->getWidth() >= $im->getHeight()) {
         $x1 = $centerX - $centerY;
         $y1 = 0;
         $x2 = $centerX + $centerY;
         $y2 = $im->getHeight();
     } else {
         $x1 = 0;
         $y1 = $centerY - $centerX;
         $x2 = $im->getWidth();
         $y2 = $centerY + $centerX;
     }
     $im->crop($x1, $y1, $x2, $y2);
     // takes care of out of boundary conditions automatically
     $im->resample(50, 50, true);
     $im->save($this->pathProfilePicThumb . $this->get('profilepic'));
 }
 public static function getGalleryPicture($img)
 {
     $imageName = 'GP_' . $img;
     $targetFile = '../../../View/img/Upload/galeri/' . $img;
     $squareImg = '../../../View/img/Upload/galeri/' . $imageName;
     $finalImg = 'http://localhost/SIMasjid/View/img/Upload/galeri/' . $imageName;
     if (copy($targetFile, $squareImg)) {
         $size = 0;
         $imS = new ImageManipulator($squareImg);
         if ($imS->getWidth() != $imS->getHeight()) {
             if ($imS->getWidth() < $imS->getHeight()) {
                 $size = $imS->getWidth();
             } else {
                 $size = $imS->getHeight();
             }
             $centreX = round($imS->getWidth() / 2);
             $centreY = round($imS->getHeight() / 2);
             $x1 = $centreX - $size / 2;
             $y1 = $centreY - $size / 2;
             $x2 = $centreX + $size / 2;
             $y2 = $centreY + $size / 2;
             $imS->crop($x1, $y1, $x2, $y2);
             $imS->save($squareImg);
             unlink($targetFile);
         }
     } else {
         $finalImg = null;
     }
     return $finalImg;
 }