Exemple #1
0
function crop400($file, $file_name, $des)
{
    require_once "lib/ImageManipulator.php";
    $im = new ImageManipulator($file);
    $x1 = 0;
    $y1 = 0;
    $x2 = 400;
    $y2 = 300;
    $im->crop($x1, $y1, $x2, $y2);
    // takes care of out of boundary conditions automatically
    $im->save($des . $file_name);
}
function crop5x3($file, $file_name, $des, $width)
{
    require_once "lib/ImageManipulator.php";
    $im = new ImageManipulator($file);
    $x1 = 0;
    $y1 = 0;
    $height = round($width * 3 / 5);
    $x2 = $width;
    $y2 = $height;
    $im->crop($x1, $y1, $x2, $y2);
    // takes care of out of boundary conditions automatically
    $im->save($des . $file_name);
}
Exemple #3
0
     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;
 }
 if ($id != "new") {
     //Process the Discipline Report
     if ($_FILES['discipline']['name']) {
         //Upload File to Server
         $validExtensions = array('.doc', '.DOC', '.docx', '.DOCX', '.pdf', '.PDF');
         $fileExtension = strrchr($_FILES['discipline']['name'], ".");
         if (in_array($fileExtension, $validExtensions)) {
             $newNamePrefix = time() . '$_$';
 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;
 }
Exemple #6
0
 /**
  * Método para manipulação da foto do perfil
  * Este método utiliza uma classe externa que não foi criada por mim
  * @return bool
  */
 protected function uploadFoto()
 {
     if (Input::exists('files')) {
         $fotoperfil = isset($_FILES[$this->colunaImagem]) ? $_FILES[$this->colunaImagem] : null;
         if ($fotoperfil['error'] > 0) {
             //echo 'Nenhuma imagem enviada.<br>';
             if (isset($_POST['webcam_photo']) && $_POST['webcam_photo'] != '') {
                 $this->uploadWebcam();
             }
         } 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->arquivoTemp);
                 $this->fotoEnviada = true;
             } else {
                 $this->fotoEnviada = false;
             }
         }
     }
 }
<?php

include_once "../config.php";
$banner = $admin_database->cleanXSS(@$_POST["banner"]);
$yAxis = $admin_database->cleanXSS(@$_POST['yAxis']);
//$banner_location = $GLOBAL_BANNER_TNB . $banner;
$banner_location = "../../uploads/banner/thumbnail/" . $banner;
$im = new ImageManipulator($banner_location);
//fb($im);
$x1 = 0;
$y1 = $yAxis;
$x2 = 780;
$y2 = 390;
$im->crop($x1, $y1, $x2, $y2);
//fb($im);
$im->save($banner_location);