Eventviva\ImageResize::resizeToWidth PHP Method

resizeToWidth() public method

Resizes image according to the given width (height proportional)
public resizeToWidth ( integer $width, boolean $allow_enlarge = false ) : static
$width integer
$allow_enlarge boolean
return static
    public function resizeToWidth($width, $allow_enlarge = false)
    {
        $ratio = $width / $this->getSourceWidth();
        $height = $this->getSourceHeight() * $ratio;
        $this->resize($width, $height, $allow_enlarge);
        return $this;
    }

Usage Example

コード例 #1
0
 public function generateThumbnail($name)
 {
     $image = new ImageResize(self::PATH_ORIGINALS . DIRECTORY_SEPARATOR . $name);
     $image->resizeToWidth(1900);
     unlink(self::PATH_ORIGINALS . DIRECTORY_SEPARATOR . $name);
     $image->save(self::PATH_ORIGINALS . DIRECTORY_SEPARATOR . $name);
     $image = new ImageResize(self::PATH_ORIGINALS . DIRECTORY_SEPARATOR . $name);
     $image->resizeToWidth(200);
     $image->save(self::PATH_THUMBNAILS . DIRECTORY_SEPARATOR . $name);
 }
All Usage Examples Of Eventviva\ImageResize::resizeToWidth