Exemplo n.º 1
0
function the_thumbnail($sizeW = 300, $sizeH = 300, $postid = null, $thumbnailid = null)
{
    if ($postid == null) {
        $postid = get_the_ID();
    }
    $size = array($sizeW, $sizeH);
    $post = get_post($postid);
    $thumbnailid = $thumbnailid == null ? get_post_thumbnail_id($post->ID) : $thumbnailid;
    $uri = wp_get_attachment_image_src($thumbnailid, 'full');
    if (!$uri) {
        return placeholdit($sizeW, $sizeH);
    }
    $filename = explode('.', substr($uri[0], strrpos($uri[0], '/') + 1));
    $extension = array_pop($filename);
    $title = implode('.', $filename);
    $upload_dir = wp_upload_dir();
    $image_path = $upload_dir['path'] . '/' . $title . '-arpt-' . $size[0] . 'x' . $size[1] . '.' . $extension;
    $image_uri = $upload_dir['url'] . '/' . $title . '-arpt-' . $size[0] . 'x' . $size[1] . '.' . $extension;
    if (file_exists($image_path)) {
        return $image_uri;
    }
    $part_uri = explode(get_site_url(), $uri[0]);
    $the_url = ABSPATH . trim($part_uri[1], '/');
    if (!file_exists($the_url)) {
        return placeholdit($sizeW, $sizeH);
    }
    try {
        $img = new abeautifulsite\SimpleImage($the_url);
        $img->thumbnail($size[0], $size[1]);
        $img->save($image_path);
    } catch (Exception $e) {
        return '';
    }
    return $image_uri;
}
Exemplo n.º 2
0
 public function reduceImage($routeDest)
 {
     $img = new \abeautifulsite\SimpleImage($this->route . $this->getFileName());
     $img->fit_to_width(300);
     $img->save();
     if ($routeDest) {
         $img->thumbnail(100, 75);
         $img->save($routeDest . $this->fileName);
     }
 }
Exemplo n.º 3
0
 function getAlbumFeed($album)
 {
     $albumFeed = array();
     $path = JPATH_SITE . '/images/com_immotoa/' . $album;
     if (is_dir($path)) {
         include JPATH_SITE . '/vendor/autoload.php';
         $photos = array_diff(scandir($path), array('..', '.', '.DS_Store'));
         foreach ($photos as $photo) {
             $albumFeed[$photo]->file_name = $photo;
             $albumFeed[$photo]->full_path = JURI::root() . 'images/com_immotoa/' . $album . '/' . $photo;
             $cropped = 'cache/com_immotoa/images/' . md5($album . $photo) . '.jpg';
             if (!file_exists(JPATH_SITE . '/' . $cropped)) {
                 $img = new abeautifulsite\SimpleImage(JPATH_SITE . '/images/com_immotoa/' . $album . '/' . $photo);
                 $img->thumbnail(512, 512);
                 $img->save(JPATH_SITE . '/cache/com_immotoa/images/' . md5($album . $photo) . '.jpg', 80);
             }
             $albumFeed[$photo]->cropped_path = JURI::root() . $cropped;
         }
         return $albumFeed;
     }
     return false;
 }
Exemplo n.º 4
0
 public function createVersion($imagePath, $sizeString = false)
 {
     if (strlen($this->urlAlias) < 1) {
         throw new \Exception('Image without urlAlias!');
     }
     $cachePath = $this->getModule()->getCachePath();
     $subDirPath = $this->getSubDur();
     $fileExtension = pathinfo($this->filePath, PATHINFO_EXTENSION);
     if ($sizeString) {
         $sizePart = '_' . $sizeString;
     } else {
         $sizePart = '';
     }
     $pathToSave = $cachePath . '/' . $subDirPath . '/' . $this->urlAlias . $sizePart . '.' . $fileExtension;
     BaseFileHelper::createDirectory(dirname($pathToSave), 0777, true);
     if ($sizeString) {
         $size = $this->getModule()->parseSize($sizeString);
     } else {
         $size = false;
     }
     if ($this->getModule()->graphicsLibrary == 'Imagick') {
         $image = new \Imagick($imagePath);
         $image->setImageCompressionQuality(100);
         if ($size) {
             if ($size['height'] && $size['width']) {
                 $image->cropThumbnailImage($size['width'], $size['height']);
             } elseif ($size['height']) {
                 $image->thumbnailImage(0, $size['height']);
             } elseif ($size['width']) {
                 $image->thumbnailImage($size['width'], 0);
             } else {
                 throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
             }
         }
         $image->writeImage($pathToSave);
     } else {
         $image = new \abeautifulsite\SimpleImage($imagePath);
         if ($size) {
             if ($size['height'] && $size['width']) {
                 $image->thumbnail($size['width'], $size['height']);
             } elseif ($size['height']) {
                 $image->fit_to_height($size['height']);
             } elseif ($size['width']) {
                 $image->fit_to_width($size['width']);
             } else {
                 throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
             }
         }
         if ($this->getModule()->waterMark) {
             if (!file_exists(Yii::getAlias($this->getModule()->waterMark))) {
                 throw new Exception('WaterMark not detected!');
             }
             $wmMaxWidth = intval($image->get_width() * 0.4);
             $wmMaxHeight = intval($image->get_height() * 0.4);
             $waterMarkPath = Yii::getAlias($this->getModule()->waterMark);
             $waterMark = new \abeautifulsite\SimpleImage($waterMarkPath);
             if ($waterMark->get_height() > $wmMaxHeight or $waterMark->get_width() > $wmMaxWidth) {
                 $waterMarkPath = $this->getModule()->getCachePath() . DIRECTORY_SEPARATOR . pathinfo($this->getModule()->waterMark)['filename'] . $wmMaxWidth . 'x' . $wmMaxHeight . '.' . pathinfo($this->getModule()->waterMark)['extension'];
                 if (!file_exists($waterMarkPath)) {
                     $waterMark->fit_to_width($wmMaxWidth);
                     $waterMark->save($waterMarkPath, 100);
                     if (!file_exists($waterMarkPath)) {
                         throw new Exception('Cant save watermark to ' . $waterMarkPath . '!!!');
                     }
                 }
             }
             $image->overlay($waterMarkPath, 'bottom right', 0.5, -10, -10);
         }
         $image->save($pathToSave, 100);
     }
     return $image;
 }
Exemplo n.º 5
0
 private function resize()
 {
     require 'SimpleImage.php';
     $path = DEF_IMG_UP_DIR . USER_ID . DS . $this->name . '.' . $this->ext;
     $t_path = DEF_IMG_UP_DIR . USER_ID . '/thumbnails';
     if (!is_dir($t_path)) {
         mkdir($t_path);
     }
     $t_path = DEF_IMG_UP_DIR . USER_ID . '/thumbnails/' . $this->name . '.' . $this->ext;
     $img = new abeautifulsite\SimpleImage($path);
     $img->thumbnail(120, 120)->save($t_path);
 }
Exemplo n.º 6
0
     if (!in_array($mime, $acceptedMime)) {
         $error = "Type de fichier refuser ";
     }
     if ($_FILES == $_SESSION['user']['pic_name']) {
     }
     if (empty($error)) {
         $extention = pathinfo($_FILES['pic_name']['name'], PATHINFO_EXTENSION);
         $pic_name = md5($tmpName . time() . uniqid()) . "." . $extention;
         $destinationDirectory = __DIR__ . "/../img/uploads/";
         if (file_exists($destinationDirectory . "originals/" . $pic_name)) {
             $pic_name = md5($tmpName . time() . uniqid()) . uniqid() . "." . $extention;
         }
         move_uploaded_file($tmpName, $destinationDirectory . "originals/" . $pic_name);
         $img = new abeautifulsite\SimpleImage($destinationDirectory . "originals/" . $pic_name);
         $img->best_fit(600, 600)->save($destinationDirectory . "mediums/" . $pic_name);
         $img->thumbnail(150, 150)->save($destinationDirectory . "thumbnails/" . $pic_name);
     }
     if (empty($error)) {
         $sql = "UPDATE users \n\t\t\t\t\tSET pic_name = :pic_name\n\t\t\t\t\tWHERE id = :id";
         $sth = $dbh->prepare($sql);
         $sth->bindValue(":id", $_SESSION['user']['id']);
         $sth->bindValue(':pic_name', $pic_name);
         $sth->execute();
         $succes = "Modification enregistrer";
     }
 }
 // insert dans la BDD
 if (empty($error)) {
     $sql = "UPDATE users \n\t\t\t\t\tSET user_name = :user_name, email = :email, bio = :bio\n\t\t\t\t\tWHERE id = :id";
     $sth = $dbh->prepare($sql);
     $sth->bindValue(":id", $_SESSION['user']['id']);
Exemplo n.º 7
0
    $command[] = '-quality ' . $thumb->options['quality'];
    if ($thumb->options['blur']) {
        $command[] = '-blur 0x' . $thumb->options['blurpx'];
    }
    $command[] = '"' . $thumb->destination->root . '"';
    exec(implode(' ', $command));
};
/**
 * GDLib Driver
 */
thumb::$drivers['gd'] = function ($thumb) {
    try {
        $img = new abeautifulsite\SimpleImage($thumb->root());
        $img->quality = $thumb->options['quality'];
        if ($thumb->options['crop']) {
            @$img->thumbnail($thumb->options['width'], $thumb->options['height']);
        } else {
            $dimensions = clone $thumb->source->dimensions();
            $dimensions->fitWidthAndHeight($thumb->options['width'], $thumb->options['height'], $thumb->options['upscale']);
            @$img->resize($dimensions->width(), $dimensions->height());
        }
        if ($thumb->options['grayscale']) {
            $img->desaturate();
        }
        if ($thumb->options['blur']) {
            $img->blur('gaussian', $thumb->options['blurpx']);
        }
        if ($thumb->options['autoOrient']) {
            $img->auto_orient();
        }
        @$img->save($thumb->destination->root);
Exemplo n.º 8
0
 public function createVersion($imagePath, $sizeString = false, $crop = true, $fitImageInCanvas = false)
 {
     if (strlen($this->urlAlias) < 1) {
         throw new \Exception('Image without urlAlias!');
     }
     $cachePath = $this->getModule()->getCachePath();
     $subDirPath = $this->getSubDur();
     $fileExtension = pathinfo($this->filePath, PATHINFO_EXTENSION);
     if ($sizeString) {
         $sizePart = '_' . $sizeString;
     } else {
         $sizePart = '';
     }
     $pathToSave = $cachePath . '/' . $subDirPath . '/' . $this->urlAlias . $sizePart . '.' . $fileExtension;
     BaseFileHelper::createDirectory(dirname($pathToSave), 0777, true);
     if ($sizeString) {
         $size = $this->getModule()->parseSize($sizeString);
     } else {
         $size = false;
     }
     if ($this->getModule()->graphicsLibrary == 'Imagick') {
         // Fixes interlaced images
         $interlaceFix = $this->interlaceFix($imagePath);
         if ($interlaceFix) {
             $image = new \Imagick();
             $image->readImageBlob($interlaceFix);
         } else {
             $image = new \Imagick($imagePath);
         }
         $image->setImageCompressionQuality(100);
         // Fixes image rotations
         $this->ImagickAutoRotateImage($image);
         // If the dimensions of the original image match the requested
         // dimensions the original image is just copied to the new path
         if ($image->getImageWidth() == $size['width'] && $image->getImageHeight() == $size['height']) {
             copy($imagePath, $pathToSave);
             return $image;
         }
         if ($size) {
             if ($size['height'] && $size['width']) {
                 if (!$crop && $fitImageInCanvas) {
                     $image = $this->fitImageInCanvas($image, $size['width'], $size['height']);
                 } elseif ($crop) {
                     $image->cropThumbnailImage($size['width'], $size['height']);
                 } else {
                     $image->resizeImage($size['width'], $size['height'], \Imagick::FILTER_HAMMING, 1, false);
                 }
             } elseif ($size['height']) {
                 $image->thumbnailImage(0, $size['height']);
             } elseif ($size['width']) {
                 $image->thumbnailImage($size['width'], 0);
             } else {
                 throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
             }
         }
         $image->writeImage($pathToSave);
     } else {
         $image = new \abeautifulsite\SimpleImage($imagePath);
         // If the dimensions of the original image match the requested
         // dimensions the original image is just copied to the new path
         if ($image->get_width() == $size['width'] && $image->get_height() == $size['height']) {
             copy($imagePath, $pathToSave);
             return $image;
         }
         if ($size) {
             if ($size['height'] && $size['width']) {
                 if ($crop) {
                     $image->thumbnail($size['width'], $size['height']);
                 } else {
                     $image->resize($size['width'], $size['height']);
                 }
             } elseif ($size['height']) {
                 $image->fit_to_height($size['height']);
             } elseif ($size['width']) {
                 $image->fit_to_width($size['width']);
             } else {
                 throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
             }
         }
         //WaterMark
         if ($this->getModule()->waterMark) {
             if (!file_exists(Yii::getAlias($this->getModule()->waterMark))) {
                 throw new Exception('WaterMark not detected!');
             }
             $wmMaxWidth = intval($image->get_width() * 0.4);
             $wmMaxHeight = intval($image->get_height() * 0.4);
             $waterMarkPath = Yii::getAlias($this->getModule()->waterMark);
             $waterMark = new \abeautifulsite\SimpleImage($waterMarkPath);
             if ($waterMark->get_height() > $wmMaxHeight or $waterMark->get_width() > $wmMaxWidth) {
                 $waterMarkPath = $this->getModule()->getCachePath() . DIRECTORY_SEPARATOR . pathinfo($this->getModule()->waterMark)['filename'] . $wmMaxWidth . 'x' . $wmMaxHeight . '.' . pathinfo($this->getModule()->waterMark)['extension'];
                 //throw new Exception($waterMarkPath);
                 if (!file_exists($waterMarkPath)) {
                     $waterMark->fit_to_width($wmMaxWidth);
                     $waterMark->save($waterMarkPath, 100);
                     if (!file_exists($waterMarkPath)) {
                         throw new Exception('Cant save watermark to ' . $waterMarkPath . '!!!');
                     }
                 }
             }
             $image->overlay($waterMarkPath, 'bottom right', 0.5, -10, -10);
         }
         $image->save($pathToSave, 100);
     }
     return $image;
 }
Exemplo n.º 9
0
 $user = $db->getUserByUserId($user_id);
 if ($user != NULL && $user['isAdmin']) {
     for ($i = 0; $i < count($_FILES['files']['name']); $i++) {
         //Get the temp file path
         $tmpFilePath = $_FILES['files']['tmp_name'][$i];
         //Make sure we have a filepath
         if ($tmpFilePath != "") {
             //Setup our new file path
             $name = $_FILES['files']['name'][$i];
             $name = str_replace(" ", "_", $name);
             $newFilePath = rand(1, 100000) . $value . "_" . $name;
             //Upload the file into the temp dir
             if (move_uploaded_file($tmpFilePath, "../images/" . $newFilePath)) {
                 try {
                     $img = new abeautifulsite\SimpleImage("../images/" . $newFilePath);
                     $img->thumbnail(160, 160)->save("../images/thumb/" . $newFilePath);
                     $result = "ok";
                     $res = $db->saveImageByProductId($product_id, $newFilePath);
                 } catch (Exception $e) {
                     $result = 'Error: ' . $e->getMessage();
                 }
                 //Handle other code here
             }
         }
     }
     /*$result = $_FILES['files'];*/
     $response["error"] = false;
     $response["result"] = $result;
     echoRespnse(200, $response);
 } else {
     $response["error"] = true;
Exemplo n.º 10
0
 public function profil()
 {
     $user = $this->getUser();
     $userManager = new UserManager();
     $error = "";
     $succes = "";
     $id = "";
     $username = "";
     $email = "";
     $firstname = "";
     $lastname = "";
     $streetname = "";
     $phonenumber = "";
     $zipcode = "";
     $pic_name = $this->getUser()['pic_name'];
     $user_name_regex = "/^[\\p{L}0-9._-]{2,100}\$/u";
     if (!empty($_POST)) {
         $id = $user["id"];
         $email = trim(strip_tags($_POST['email']));
         $username = trim(strip_tags($_POST['username']));
         $firstname = trim(strip_tags($_POST['firstname']));
         $lastname = trim(strip_tags($_POST['lastname']));
         $streetname = trim(strip_tags($_POST['streetname']));
         $zipcode = trim(strip_tags($_POST['zipcode']));
         $phonenumber = trim(strip_tags($_POST['phonenumber']));
         //|||||||||||||||||||| username valide ?
         if (strlen($username) < 4) {
             $error = "Votre Pseudo doit comporter 4 lettres minimum !";
         }
         if (!preg_match($user_name_regex, $username)) {
             $error = "Votre Pseudo ne doit pas contenir de caractère spéciaux !";
         } else {
             if ($username !== $_SESSION['user']['username']) {
                 $foundPseudo = $userManager->usernameExists($username);
                 if (!empty($foundPseudo)) {
                     $error = "Ce pseudo est déjà enregistré ici !";
                 }
             }
         }
         //|||||||||||||||| Email valide ?
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $error = "Email non valide";
         } else {
             if ($email !== $_SESSION['user']['email']) {
                 $foundEmail = $userManager->emailExists($email);
                 if (!empty($foundEmail)) {
                     $error = "Ce pseudo est déjà enregistré ici !";
                 }
             }
         }
         // |||||||||||||||| IMAGE valide ?
         if ($_FILES['pic_name']['error'] != 4) {
             $tmpName = $_FILES['pic_name']['tmp_name'];
             if ($_FILES['pic_name']['error'] != 0) {
                 switch ($_FILES['pic_name']['error']) {
                     case 1:
                         $error = "Votre fichier est trop gros !";
                         break;
                     case 4:
                         $error = "Aucun fichier n'a été selectionné !";
                         break;
                     default:
                         $error = "Une erreur est survenue lors du chargement de votre image LOL";
                         break;
                 }
             }
             $info = finfo_open(FILEINFO_MIME_TYPE);
             $mime = finfo_file($info, $tmpName);
             $acceptedMime = array("image/jpeg", "image/gif", "image/png");
             if (!in_array($mime, $acceptedMime)) {
                 $error = "Type de fichier refuser ";
             }
             if ($_FILES == $_SESSION['user']['pic_name']) {
             }
             if (empty($error)) {
                 $extention = pathinfo($_FILES['pic_name']['name'], PATHINFO_EXTENSION);
                 $pic_name = md5($tmpName . time() . uniqid()) . "." . $extention;
                 $destinationDirectory = __DIR__ . "/../../public/assets/img/uploads/";
                 if (file_exists($destinationDirectory . "originals/" . $pic_name)) {
                     $pic_name = md5($tmpName . time() . uniqid()) . uniqid() . "." . $extention;
                 }
                 move_uploaded_file($tmpName, $destinationDirectory . "originals/" . $pic_name);
                 $img = new \abeautifulsite\SimpleImage($destinationDirectory . "originals/" . $pic_name);
                 $img->best_fit(600, 600)->save($destinationDirectory . "mediums/" . $pic_name);
                 $img->thumbnail(150, 150)->save($destinationDirectory . "thumbnails/" . $pic_name);
             }
             if (empty($error)) {
                 $succes = "Bravo !";
             }
         }
         //|||||||||||||||| ZIPCODE valide ?
         if ($zipcode <= "75000" || $zipcode >= "75021") {
             $error = "Vous devez habiter Paris pour vous inscrire à notre service !";
         }
         //|||||||||||||||| Téléphone valide ?
         if (preg_match("/^[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}\$/", $phonenumber)) {
             // $phonenumber is valid
             $error = "Votre numéro de téléphone n'est pas valide !";
         }
         //||||||||||||||||	2er cihffre du Telephone coresponde a 01,02,03,04,05,06,07,08 ou 09
         if (substr($phonenumber, 0, 2) < "01" || substr($phonenumber, 0, 2) > "09") {
             $error = "Votre numéro de téléphone n'est pas valide !";
         }
         //si valide...
         if (empty($error)) {
             //insérer en base
             $modifySubscriber = ["username" => $username, "email" => $email, "firstname" => $firstname, "lastname" => $lastname, "zip_code" => $zipcode, "street_name" => $streetname, "phone_number" => $phonenumber, "date_modified" => date("Y-m-d H:i:s"), "pic_name" => $pic_name];
             $userManager = new \Manager\UserManager();
             $userManager->update($modifySubscriber, $id);
             //Crée une instance et refresh le contenu
             $am = new AuthentificationManager();
             $am->refreshUser();
             $succes = "Votre profil a bien été enregistré !";
         }
     }
     $data = [];
     $data['error'] = $error;
     $data['succes'] = $succes;
     $data['username'] = $username;
     $data['email'] = $email;
     $data['firstname'] = $firstname;
     $data['lastname'] = $lastname;
     $data['zipcode'] = $zipcode;
     $data['streetname'] = $streetname;
     $data['phonenumber'] = $phonenumber;
     $data['pic_name'] = 'default.png';
     $this->show('user/profile', $data);
 }
Exemplo n.º 11
0
         //nouveau nom du fichier, sécuritaire (contre les XSS, les espaces, les guillemets, etc.)
         $newName = md5($tmpName . time() . uniqid()) . "." . $ext;
         //chemin vers le répertoire où nous déplacerons l'image
         $destinationDirectory = __DIR__ . "/img/uploads/";
         //si le fichier existe déjà avec ce nom (malheureux hasard)
         if (file_exists($destinationDirectory . "originals/" . $newName)) {
             //on ajoute un identifiant unique à la fin du fichier
             $newName = md5($tmpName . time() . uniqid()) . uniqid() . "." . $ext;
         }
         //déplace le fichier temporaire vers un autre répertoire sur notre serveur
         move_uploaded_file($tmpName, $destinationDirectory . "originals/" . $newName);
         $img = new abeautifulsite\SimpleImage($destinationDirectory . "originals/" . $newName);
         //mediums
         $img->best_fit(600, 600)->save($destinationDirectory . "mediums/" . $newName);
         //thumbnails
         $img->thumbnail(150, 150)->sepia()->save($destinationDirectory . "thumbnails/" . $newName);
         $sql = "UPDATE message \n\t\t\tSET mess_picture = :mess_picture\n\t\t\n\t\t\tWHERE id_mess = :id_mess";
         $sth = $dbh->prepare($sql);
         $sth->bindValue(":mess_picture", $newName);
         // $sth->bindValue(":user_picture", $user_picture);
         $sth->bindValue(":id_mess", $dbh->lastInsertId());
         // $sth->bindValue(":user_picture", $user_picture);
         $sth->execute();
     } else {
         //rediriger avec un message d'erreur vers la page contenant le form
         echo $error;
     }
 }
 // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 //      AFFICHAGE MESSAGE SUR PAGE PROFIL.PHP
 $sql = "SELECT description\n\t\t\t\tFROM message \n\t\t\t\tORDER BY date_created DESC\n\t\t\t\tLIMIT 5";
Exemplo n.º 12
0
 private function save_user_photo($album_id, $new_file_name)
 {
     if ($album_id) {
         $user_albums = $this->profile_model->get_all_users_albums();
         if (in_array($album_id, $user_albums)) {
             ini_set('memory_limit', '256M');
             include './third_part/SimpleImage.php';
             try {
                 copy($this->user_photo_uploads_dir . $new_file_name, $this->user_photo_save_dir . 'original_' . $new_file_name);
                 $img = new abeautifulsite\SimpleImage($this->user_photo_uploads_dir . $new_file_name);
                 $wim = $img->get_width();
                 $him = $img->get_height();
                 if ($wim > $him) {
                     $razn = round(($wim - $him) / 2);
                     $top_x = $razn;
                     $top_y = 0;
                     $bottom_x = $wim - $razn;
                     $bottom_y = $him;
                     if ($wim > 500) {
                         $img->fit_to_width(500)->save($this->user_photo_save_dir . '500_' . $new_file_name);
                     } else {
                         $img->save($this->user_photo_save_dir . '500_' . $new_file_name);
                     }
                     $img->thumbnail(140, 140, 'center')->save($this->user_photo_save_dir . '140_' . $new_file_name);
                 } elseif ($him > $wim) {
                     $razn = round(($wim - $him) / 2);
                     $top_x = 0;
                     $top_y = $razn;
                     $bottom_x = $wim;
                     $bottom_y = $him - $razn;
                     if ($him > 500 & $wim > 500) {
                         $img->fit_to_width(500)->save($this->user_photo_save_dir . '500_' . $new_file_name);
                     } else {
                         $img->save($this->user_photo_save_dir . '500_' . $new_file_name);
                     }
                     $img->thumbnail(140, 140, 'center')->save($this->user_photo_save_dir . '140_' . $new_file_name);
                 } else {
                     if ($wim > 500) {
                         $img->fit_to_width(500)->save($this->user_photo_save_dir . '500_' . $new_file_name);
                     } else {
                         $img->save($this->user_photo_save_dir . '500_' . $new_file_name);
                     }
                     $img->thumbnail(140, 140, 'center')->save($this->user_photo_save_dir . '140_' . $new_file_name);
                 }
             } catch (Exception $e) {
                 echo json_encode(array("error" => -1, 'error_message' => $e->getMessage()));
             }
             if (file_exists($this->user_photo_save_dir . 'original_' . $new_file_name) && file_exists($this->user_photo_save_dir . '500_' . $new_file_name) && file_exists($this->user_photo_save_dir . '140_' . $new_file_name)) {
                 unlink($this->user_photo_uploads_dir . $new_file_name);
                 if ($this->profile_model->save_photo_to_album($new_file_name, $album_id, $wim, $him)) {
                     $file_id = $this->profile_model->get_file_id_by_file_name($new_file_name);
                     echo json_encode(array('file_name' => $new_file_name, "file_id" => $file_id, "width" => $wim, "height" => $him, "success" => 1));
                 } else {
                     unlink($this->user_photo_save_dir . 'original_' . $new_file_name);
                     unlink($this->user_photo_save_dir . '500_' . $new_file_name);
                     unlink($this->user_photo_save_dir . '140_' . $new_file_name);
                     echo json_encode(array("error" => -1, 'error_message' => 'You have exceeded the number of photos!', 'error_type' => 'error_count'));
                 }
             } else {
                 unlink($this->user_photo_uploads_dir . $new_file_name);
                 echo json_encode(array("error" => -1, 'error_message' => 'Unknown error!', 'error_type' => 'unknown_error'));
             }
         } else {
             echo json_encode(array("error" => -1, 'error_message' => 'Album doesn`t exists!', 'error_type' => 'error_album_exist'));
         }
     } else {
         echo json_encode(array("error" => -1, 'error_message' => 'Album doesn`t exists!', 'error_type' => 'error_album_exist'));
     }
 }