fit_to_width() public method

Fit to width (proportionally resize to specified width)
public fit_to_width ( integer $width ) : SimpleImage
$width integer
return SimpleImage
Beispiel #1
0
 if (!empty($_POST['_height']) && !empty($_POST['_width'])) {
     $imageClass->resize($_POST['_width'], $_POST['_height']);
 } elseif (!empty($_POST['_height'])) {
     $imageClass->fit_to_height($_POST['_height']);
 } else {
     $imageClass->fit_to_width($_POST['_width']);
 }
 //$imageClass->contrast(50);
 $imageClass->save('../../../user_upload/' . $newName, $_POST['_quality']);
 $imageClass->resize(200, 200);
 $imageClass->save('../../../user_upload/thumb_200/' . $newName, 90);
 $imageClass1 = new SimpleImage('../../../user_upload/' . $newName);
 $imageClass1->fit_to_width(400);
 $imageClass1->save('../../../user_upload/thumb_400/' . $newName, $_POST['_quality']);
 $imageClass2 = new SimpleImage('../../../user_upload/' . $newName);
 $imageClass2->fit_to_width(800);
 $imageClass2->save('../../../user_upload/thumb_800/' . $newName, $_POST['_quality']);
 if ($i == 1) {
     mysql_query("INSERT INTO vbildkategorie SET katName='" . $_POST['_newCategory1'] . "',katParent='" . $_POST['_inCategory'] . "'");
     $insertCategoryId = mysql_insert_id();
 }
 mysql_query("INSERT INTO vbilder SET bildName='" . $newName . "',bildFile='" . $newName . "',bildKat='" . $insertCategoryId . "'");
 $imageId = mysql_insert_id();
 if (!empty($_POST['_createGallery']) && $i == 1) {
     mysql_query("INSERT INTO vbildergalerien SET galName='" . mysql_escape_string($_POST['_galleryName']) . "',galBilder='" . $imageId . "'");
     $idInsertGallery = mysql_insert_id();
 } else {
     $query = mysql_query("SELECT * FROM vbildergalerien WHERE galID = '" . $idInsertGallery . "'");
     $row = mysql_fetch_array($query);
     $images = $row['galBilder'] . ';' . $imageId;
     mysql_query("UPDATE vbildergalerien SET galBilder='" . $images . "' WHERE galID='" . $idInsertGallery . "'");
Beispiel #2
0
    $file = '';
}
if (empty($file) || !file_exists($root . $file)) {
    $file = '/noimage.jpg';
}
echo $file;
exit;
$fileRes = '/resize/' . $height . '/' . $width . '/' . $type . $file;
$file = $root . $file;
$fileRes = $root . $fileRes;
if (!file_exists($fileRes)) {
    require_once $root . '/SimpleImage.php';
    $simpleImage = new SimpleImage();
    $simpleImage->load($file);
    switch ($type) {
        case 'no':
            $simpleImage->square_crop($height, $width);
            break;
        case 'w':
            $simpleImage->fit_to_width($width);
            break;
        case 'h':
            $simpleImage->fit_to_height($height);
            break;
        case 's':
            $simpleImage->resize($height, $width);
            break;
    }
    createFolders($fileRes);
    $simpleImage->save($fileRes);
}
 function resizeImage($source_image, $target_image, $width = 0, $height = 0, $best_fit = false)
 {
     $SimpleImage = new SimpleImage($source_image);
     if ($best_fit) {
         $SimpleImage->best_fit($width, $height)->save($target_image, 100);
     } else {
         if (!$width && !$height) {
             $SimpleImage->save($target_image);
         } elseif ($SimpleImage->get_width() >= $width) {
             $SimpleImage->fit_to_width($width)->crop(0, 0, $width, $SimpleImage->get_height() > $height ? $height : $SimpleImage->get_height())->save($target_image);
         } elseif ($SimpleImage->get_height() >= $height) {
             $SimpleImage->fit_to_width($height)->crop(0, 0, $SimpleImage->get_width() > $width ? $width : $SimpleImage->get_width(), $height)->save($target_image);
         } else {
             $SimpleImage->best_fit($width, $height)->save($target_image);
         }
     }
 }
Beispiel #4
0
 /**
  * Verify and validate the extension of the uploaded file.
  *
  * @param string $name
  * @param string $type
  * @return boolean
  */
 public function validateSponsorImage($name, $tmpName, $type)
 {
     $allowedExtensions = array("gif", "jpeg", "jpg", "png", "pdf", "GIF", "JPEG", "JPG", "PNG", "PDF");
     $temp = explode(".", $name);
     $extension = end($temp);
     if (($type === "image/gif" || $type === "image/jpeg" || $type === "image/jpg" || $type === "image/pjpeg" || $type === "image/x-png" || $type === "image/png" || $type === "application/pdf") && in_array($extension, $allowedExtensions)) {
         $img = new SimpleImage($tmpName);
         $img->fit_to_width(360);
         $img->invert();
         $img->crop(0, ($img->get_height() - 190) / 2, 360, ($img->get_height() - 190) / 2 + 190);
         $img->invert();
         $img->save("_temp/_img.png");
         return true;
     } else {
         return false;
     }
 }