Dimension::withWidth

Gets new image dimension with defined width.

@param int $newWidth New image width.

@return \O2System\Image\Dimension
485702
public function withWidth($newWidth)
    {
        return $this->withSize($newWidth, ceil($newWidth * $this->height / $this->width));
    }
203170
public function getWidth() : int
    {
        if (!$this->loadImageInfo()) {
            throw InvalidOperationException::format(
                    'Invalid call to %s: file \'%s\' is not a valid image',
                    __METHOD__,
                    $this->fullPath
            );
        }

        return $this->width;
    }
1284034
private function getSizeByFixedWidth($newWidth, $newHeight)
	{
		// *** If forcing is off...
		if ( ! $this->forceStretch)
		{

			// *** ...check if actual width is less than target width
			if ($this->width < $newWidth)
			{
				return array( 'optimalWidth' => $this->width, 'optimalHeight' => $this->height );
			}
		}

		$ratio = $this->height / $this->width;

		$newHeight = $newWidth * $ratio;

		//return $newHeight;
		return array( 'optimalWidth' => $newWidth, 'optimalHeight' => $newHeight );
	}
1057622
public function getWidth($withUnit = false)
    {
        if ($withUnit) {
            return sprintf('%d %s', $this->width, $this->unit);
        }

        return $this->width;
    }
986560
public function getWidth()
    {
      if ($this->width != null) {
        return $this->width;
      }

      list($width) = getimagesize($this->_files['tmp_name']);

      return $width;
    }
634801
public function resizeByWidth($width)
    {
        return $this->createCloneWithResource(
            function (InterventionImage $resource) use ($width) {
                return $resource->widen($width);
            }
        );
    }
1189306
public function withScale($scale)
    {
        $newDimension = clone $this;

        return $newDimension->withSize(
            round($this->width * ($scale / 100)),
            round($this->height * ($scale / 100))
        );
    }
92601
public function resizeIn($maxWidth, $maxHeight, $minWidth = null, $minHeight = null)
        {
            $this->_maxWidth = $maxWidth;
            $this->_maxHeight = $maxHeight;
            $this->_minWidth = $minWidth;
            $this->_minHeight = $minHeight;

            $this->_generateThumb();

            $this->_source = $this->_thumb;
            $this->_reloadSize();

            return $this;
        }
921378
public function setWidth(int $width) : AbstractResize
    {
        if ($width < 1) {
            throw new \InvalidArgumentException(Helper::ERROR_WIDTH_INVALID);
        }

        $this->canvas['width'] = $width;

        return $this;
    }
241232
private function getDimensions($newWidth, $newHeight, $option)
		# Author:     Jarrod Oberto
		# Date:       17-11-09
		# Purpose:    Get new image dimensions based on user specificaions
		# Param in:   $newWidth:
		#             $newHeight:
		# Param out:  Array of new width and height values
		# Reference:
		# Notes:    If $option = 3 then this function is call recursivly
		#
		#       To clarify the $option input:
		#               0 = The exact height and width dimensions you set.
		#               1 = Whatever height is passed in will be the height that
		#                   is set. The width will be calculated and set automatically
		#                   to a the value that keeps the original aspect ratio.
		#               2 = The same but based on the width.
		#               3 = Depending whether the image is landscape or portrait, this
		#                   will automatically determine whether to resize via
		#                   dimension 1,2 or 0.
		#               4 = Resize the image as much as possible, then crop the
		#         remainder.
	{

		switch (strval($option))
		{
			case '0':
			case 'exact':
				$optimalWidth = $newWidth;
				$optimalHeight = $newHeight;
				break;
			case '1':
			case 'portrait':
				$dimensionsArray = $this->getSizeByFixedHeight($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
			case '2':
			case 'landscape':
				$dimensionsArray = $this->getSizeByFixedWidth($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
			case '3':
			case 'auto':
				$dimensionsArray = $this->getSizeByAuto($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
			case '4':
			case 'crop':
				$dimensionsArray = $this->getOptimalCrop($newWidth, $newHeight);
				$optimalWidth = $dimensionsArray['optimalWidth'];
				$optimalHeight = $dimensionsArray['optimalHeight'];
				break;
		}

		return array( 'optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight );
	}
931469
protected function actionThumbsRebuildStart($newWidth, $newHeight)
    {
        $table = ORM::getTable(Eresus_Plugin_Registry::getInstance()->load('gallery'), 'Image');
        $images = $table->findAll();

        $ids = array();
        foreach ($images as $image)
        {
            $ids []= $image->id;
        }
        return array('action' => 'start', 'ids' => $ids, 'width' => $newWidth, 'height' => $newHeight);
    }
1188750
public function getImageResizeDefinitionByWidth($width)
    {
        if (!key_exists($width, $this->irds)) {
            throw new WidthNotAllowedException($width);
        }
        return $this->irds[$width];
    }
1057398
public function setWidth($width)
    {
        foreach ($this->results as $name) {
            $this->columns->offsetGet($name)->setWidth($width);
        }

        return $this;
    }
392918
public function setWidth($width)
    {
        if (is_int($width) === true) {
            $this->width = $width;
        } else {
            $msg = "The 'width' argument must be an integer, '" . gettype($width) . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
1252978
public function setImageWidth( $width )
    {
        $this->imageWidth = empty( $width ) ? null : (int) $width;
        return $this;
    }
1146589
private function get_size_by_auto($new_width, $new_height)
    {
        // Image to be resized is wider (landscape)
        if ($this->height < $this->width) {
            $optimal_width  = $new_width;
            $optimal_height = $this->get_size_by_fixed_width($new_width);
        }
        // Image to be resized is taller (portrait)
        elseif ($this->height > $this->width) {
            $optimal_width  = $this->get_size_by_fixed_height($new_height);
            $optimal_height = $new_height;
        }
        // Image to be resizerd is a square
        else {
            if ($new_height < $new_width) {
                $optimal_width  = $new_width;
                $optimal_height = $this->get_size_by_fixed_width($new_width);
            } elseif ($new_height > $new_width) {
                $optimal_width  = $this->get_size_by_fixed_height($new_height);
                $optimal_height = $new_height;
            } else {
                // Sqaure being resized to a square
                $optimal_width  = $new_width;
                $optimal_height = $new_height;
            }
        }

        return array(
            'optimal_width'  => $optimal_width,
            'optimal_height' => $optimal_height,
        );
    }
627948
public final function setWidth( int $width ) : Size
   {

      $this->triggerFixedErrorByNeed( 'width-change' );

      $this->_width = \max( $width, 0 );

      return $this;

   }