SimpleImage::fit_to_width PHP Method

fit_to_width() public method

Fit to width (proportionally resize to specified width)
public fit_to_width ( integer $width ) : SimpleImage
$width integer
return SimpleImage
    function fit_to_width($width)
    {
        $aspect_ratio = $this->height / $this->width;
        $height = $width * $aspect_ratio;
        return $this->resize($width, $height);
    }

Usage Example

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 . "'");
All Usage Examples Of SimpleImage::fit_to_width