Пример #1
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);
     }
 }
Пример #2
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;
}
Пример #3
0
 public function insertPhotoEntry($data)
 {
     $albumId = $data['album'];
     $photoName = $data['name'];
     $path = JPATH_SITE . '/images/com_immotoa/' . $albumId;
     $info = pathinfo($photoName);
     $extension = $info['extension'];
     // get the extension of the file
     $filename = $info['filename'];
     // get the extension of the file
     if (!is_dir($path)) {
         mkdir($path);
         chmod($path, 0755);
     }
     include JPATH_SITE . '/vendor/autoload.php';
     $img = new abeautifulsite\SimpleImage($data['file']);
     $img->auto_orient()->best_fit(2048, 2048);
     $img->save($path . '/' . $photoName, 90);
     return true;
 }
Пример #4
0
 public function checkAddSmallProfileImage($profileImage)
 {
     $file = new File();
     $file->Load('name = ?', array($profileImage->name . "_small"));
     if (empty($file->id)) {
         LogManager::getInstance()->info("Small profile image " . $profileImage->name . "_small not found");
         $largeFileUrl = $this->getFileUrl($profileImage->name);
         $file->name = $profileImage->name . "_small";
         $signInMappingField = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME;
         $file->{$signInMappingField} = $profileImage->{$signInMappingField};
         $file->filename = $file->name . str_replace($profileImage->name, "", $profileImage->filename);
         $file->file_group = $profileImage->file_group;
         file_put_contents("/tmp/" . $file->filename . "_orig", file_get_contents($largeFileUrl));
         if (file_exists("/tmp/" . $file->filename . "_orig")) {
             //Resize image to 100
             $img = new abeautifulsite\SimpleImage("/tmp/" . $file->filename . "_orig");
             $img->fit_to_width(100);
             $img->save("/tmp/" . $file->filename);
             $uploadFilesToS3Key = SettingsManager::getInstance()->getSetting("Files: Amazon S3 Key for File Upload");
             $uploadFilesToS3Secret = SettingsManager::getInstance()->getSetting("Files: Amazone S3 Secret for File Upload");
             $s3Bucket = SettingsManager::getInstance()->getSetting("Files: S3 Bucket");
             $uploadname = CLIENT_NAME . "/" . $file->filename;
             $localFile = "/tmp/" . $file->filename;
             $s3FileSys = new S3FileSystem($uploadFilesToS3Key, $uploadFilesToS3Secret);
             $result = $s3FileSys->putObject($s3Bucket, $uploadname, $localFile, 'authenticated-read');
             unlink("/tmp/" . $file->filename);
             unlink("/tmp/" . $file->filename . "_orig");
             LogManager::getInstance()->info("Upload Result:" . print_r($result, true));
             if (!empty($result)) {
                 $ok = $file->Save();
             }
             return $file;
         }
         return null;
     }
     return $file;
 }
Пример #5
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']);
                 $image->best_fit($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;
 }
Пример #6
0
# Remove potential http://
if (strpos($src, 'http://') === 0) {
    $src = preg_replace('/http:\\/\\/(.*?)\\//', '/', $src);
}
# See if it's cached
$cacheSrc = md5(implode($_GET));
$cacheSrc = 'cache/' . $cacheSrc . '.' . $ext;
if (file_exists($cacheSrc)) {
    try {
        $img = new abeautifulsite\SimpleImage($cacheSrc);
        $img->output();
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    die;
}
# OLD SIMPLE IMAGE CODE
# Get the rest of the params TODO: Add all options: https://github.com/claviska/SimpleImage
$blur = isset($_GET['blur']) ? $_GET['blur'] : false;
# Run SimpleImage
try {
    $img = new abeautifulsite\SimpleImage($docRoot . $src);
    # TODO: Add all options
    if ($blur > 0) {
        $img->blur('gaussian', $blur);
    }
    $img->save($cacheSrc);
    $img->output();
} catch (Exception $e) {
    echo $e->getMessage();
}
Пример #7
0
    $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);
    } catch (Exception $e) {
        $thumb->error = $e;
    }
};
Пример #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;
 }
Пример #9
0
$marginbottom = $_POST['gutterBottom'] * $sourceK;
$image = new abeautifulsite\SimpleImage($sourceImage);
$image_watermark = new abeautifulsite\SimpleImage($watermark);
if ($watermarkK > 1) {
    $imgInfo = getimagesize($watermark);
    $newWidth = $imgInfo[0] / $watermarkK;
    $newHeight = $imgInfo[1] / $watermarkK;
    $image_watermark = $image_watermark->resize($newWidth, $newHeight);
    $image_watermark->save($watermark);
}
if ($mode == 'tiling') {
    $sourceSize = getimagesize($sourceImage);
    $watermarkSize = getimagesize($watermark);
    $sourceWidth = $sourceSize[0];
    $sourceHeight = $sourceSize[1];
    $offsetX = $left;
    //$data = $sourceWidth;
    for ($top; $top < $sourceHeight; $top += $watermarkSize[1] + $marginbottom) {
        for ($offsetX; $offsetX < $sourceWidth; $offsetX += $watermarkSize[0] + $marginleft) {
            $image->overlay($image_watermark, 'top left', $opacity, $offsetX, $top);
        }
        $offsetX = $left;
    }
} elseif ($mode == 'alone') {
    $image->overlay($image_watermark, 'top left', $opacity, $positionX, $positionY);
}
$result_name = time() . '.png';
$image->save('uploads/' . $result_name);
$data = '/server/uploads/' . $result_name;
echo json_encode($data);
exit;
Пример #10
0
 public function save()
 {
     $eqApp = new Apps();
     $getFinfo_q = 'SELECT * FROM cms_records 
                    WHERE 
                    fieldsetid = "' . $_POST['fieldsetid'] . '" 
                    ORDER BY sortorder ASC';
     $getFinfo_r = mysql_query($getFinfo_q);
     $getFinfo_n = mysql_num_rows($getFinfo_r);
     $pnum = 1;
     $checkPosted = 0;
     //START INSERT QUERY BEGINNING WITH USUAL STARTING VALUES
     $query_q = 'UPDATE cms_content SET ';
     //WHILE LOOP FOR ADDING THE DATABASE VALUES
     while ($getFinfo = mysql_fetch_array($getFinfo_r)) {
         switch ($getFinfo['type']) {
             case "file":
                 if (isset($_FILES[$_POST['recordset'] . '_' . $getFinfo['db_name']]["name"])) {
                     $fileInput = rand() . $_FILES[$_POST['recordset'] . '_' . $getFinfo['db_name']]["name"];
                     if (!file_exists('../uploads/' . $_POST['id'] . '/')) {
                         mkdir('../uploads/' . $_POST['id'] . '/', 0777);
                     }
                     if (!file_exists('../uploads/' . $_POST['id'] . '/' . $getFinfo['db_name'])) {
                         mkdir('../uploads/' . $_POST['id'] . '/' . $getFinfo['db_name'], 0777);
                     } else {
                         foreach (glob('../uploads/' . $_POST['id'] . '/' . $getFinfo['db_name'] . '/*') as $file) {
                             if (is_dir($file)) {
                                 recursiveRemoveDirectory($file);
                             } else {
                                 unlink($file);
                             }
                         }
                     }
                     move_uploaded_file($_FILES[$_POST['recordset'] . '_' . $getFinfo['db_name']]["tmp_name"], '../uploads/' . $_POST['id'] . '/' . $getFinfo['db_name'] . '/' . $filename . '.' . $fileext);
                     $query_q .= ($pnum > 1 ? ", " : " ") . $getFinfo['db_name'] . '="' . $fileInput . '" ';
                     $checkPosted++;
                 }
                 break;
             case "photo":
                 if (!empty($_FILES[$_POST['recordset'] . '_' . $getFinfo['db_name']]["name"])) {
                     if (!file_exists('../uploads/' . $_POST['id'] . '/')) {
                         mkdir('../uploads/' . $_POST['id'] . '/', 0777);
                     }
                     if (!file_exists('../uploads/' . $_POST['id'] . '/' . $getFinfo['db_name'])) {
                         mkdir('../uploads/' . $_POST['id'] . '/' . $getFinfo['db_name'], 0777);
                     } else {
                         foreach (glob('../uploads/' . $_POST['id'] . '/' . $getFinfo['db_name'] . '/*') as $file) {
                             if (is_dir($file)) {
                                 recursiveRemoveDirectory($file);
                             } else {
                                 unlink($file);
                             }
                         }
                     }
                     $filename = pathinfo($_FILES[$_POST['recordset'] . '_' . $getFinfo['db_name']]["name"], PATHINFO_FILENAME);
                     $fileext = strtolower(pathinfo($_FILES[$_POST['recordset'] . '_' . $getFinfo['db_name']]["name"], PATHINFO_EXTENSION));
                     $filename = strtolower(rand() . $filename);
                     $img = new abeautifulsite\SimpleImage($_FILES[$_POST['recordset'] . '_' . $getFinfo['db_name']]['tmp_name']);
                     $img->fit_to_width(300)->save('../uploads/' . $_POST['id'] . '/' . $getFinfo['db_name'] . '/300xauto_' . $filename . '.' . $fileext);
                     $img->save('../uploads/' . $_POST['id'] . '/' . $getFinfo['db_name'] . '/' . $filename . '.' . $fileext);
                     move_uploaded_file($_FILES[$_POST['recordset'] . '_' . $getFinfo['db_name']]["tmp_name"], '../uploads/' . $_POST['id'] . '/' . $getFinfo['db_name'] . '/' . $filename . '.' . $fileext);
                     $query_q .= ($pnum > 1 ? ", " : " ") . $getFinfo['db_name'] . '="' . $filename . '.' . $fileext . '" ';
                     $checkPosted++;
                 }
                 break;
             case "html":
                 $query_q .= ($pnum > 1 ? ", " : " ") . $getFinfo['db_name'] . '="' . addslashes(htmlspecialchars($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']])) . '" ';
                 $checkPosted++;
                 break;
             case "yesno":
                 $query_q .= ($pnum > 1 ? ", " : " ") . $getFinfo['db_name'] . '="' . $_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']] . '" ';
                 $checkPosted++;
                 break;
             case "multiselect":
             case "checkboxes":
                 $vals = "";
                 $x = 0;
                 if (isset($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']])) {
                     foreach ($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']] as $key => $value) {
                         $x++;
                         $vals .= $value . ($x < count($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']]) ? "," : "");
                     }
                     $query_q .= ($pnum > 1 ? ", " : " ") . $getFinfo['db_name'] . '="' . $vals . '" ';
                     $checkPosted++;
                 }
                 break;
             case "radio":
                 $vals = "";
                 $x = 0;
                 if (!empty($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']])) {
                     $query_q .= ($pnum > 1 ? ", " : " ") . $getFinfo['db_name'] . '="' . htmlspecialchars($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']]) . '" ';
                     $checkPosted++;
                 }
                 break;
             case "foreignkey":
                 $fkeyOptions = $eqApp->get_field_options($getFinfo['options'], $pnum - 1);
                 if ($fkeyOptions['record_fkeytype'] == "select") {
                     $query_q .= ($pnum > 1 ? ", " : " ") . $getFinfo['db_name'] . '="' . htmlspecialchars($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']]) . '" ';
                     $checkPosted++;
                 } elseif ($fkeyOptions['record_fkeytype'] == "multiselect") {
                     $vals = '';
                     if (isset($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']])) {
                         $d = 0;
                         foreach ($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']] as $key => $value) {
                             $d++;
                             $vals .= htmlspecialchars($value) . ($d < count($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']]) ? "," : "");
                         }
                     }
                     $query_q .= ($pnum > 1 ? ", " : " ") . $getFinfo['db_name'] . '="' . $vals . '" ';
                     $checkPosted++;
                 }
                 break;
             case "custom_url":
                 $custom_url = ltrim(rtrim($getFinfo['custom_url'], '/'), '/');
                 $perma = explode('/', $custom_url);
                 $postedCustomUrl = "";
                 $ddnum = 0;
                 foreach ($perma as $links) {
                     $ddnum++;
                     if (isset($_POST[$links])) {
                         $postedCustomUrl .= $eqApp->permaLink($_POST[$links]) . '/';
                     }
                 }
                 $postedCustomUrl = rtrim($postedCustomUrl, '/');
                 $checkCU_q = 'SELECT * FROM cms_content 
                                     WHERE 
                                     custom_url = "' . $postedCustomUrl . '" 
                                     AND id <> "' . $_POST['id'] . '"';
                 $checkCU_r = mysql_query($checkCU_q);
                 $query_q .= ($pnum > 1 ? ", " : " ") . $getFinfo['db_name'] . '="' . $postedCustomUrl . (mysql_num_rows($checkCU_r) > 0 ? rand() : '') . '" ';
                 $checkPosted++;
                 break;
             default:
                 //for text,textarea,colorpicker,date,select
                 $query_q .= ($pnum > 1 ? ", " : " ") . $getFinfo['db_name'] . '="' . htmlspecialchars($_POST[$_POST['recordset'] . '_' . $getFinfo['db_name']]) . '" ';
                 $checkPosted++;
                 break;
         }
         $pnum++;
     }
     $query_q .= 'WHERE id = "' . $_POST['id'] . '"';
     if ($checkPosted > 0) {
         mysql_query($query_q) or die(mysql_error());
     }
     exit;
 }
Пример #11
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'));
     }
 }