fitInBounds

@param int $w maximum width
@param int $h maximum height
@param int $width
@param int $height

@access protected
@return mixed
181368
protected function fitInBounds($w, $h, $width, $height)
    {
        if ($width >= $w or $height >= $h) {

            $ratA = $this->ratio($width, $height);
            $ratM = min($ratA, $this->ratio($w, $h));

            $isR = $ratM === $ratA;

            $valW = (int)round($h * $ratM);
            $valH = (int)round($w / $ratA);

            list($width, $height) = $width <= $height ? [$valW, $isR ? $h : $valH] : [$isR ? $w : $valW, $valH];
        }

        return compact('width', 'height');
    }
214802
public function fit_to_width($width)
    {
        $aspect_ratio = $this->height / $this->width;
        $height = $width * $aspect_ratio;

        return $this->resize($width, $height);
    }
726202
public void setBounds(float x, float y, float width, float height) {
		setX(x);
		setY(y);
		setSize(width, height);
	}
774659
public function setSize($width = 0, $height = 0)
    {
        if (!empty($width) && !empty($height)) {
            $this->width = $this->boxWidth = $width;
            $this->height = $this->boxHeight = $height;
        }

        return $this;
    }
1283642
public function setSize($width, $height)
    {
        $this->width = $width;
        $this->height = $height;

        return $this;
    }
539068
public function resize_fit($width, $height) {
        if ((!$width && !$height) || (($width == $this->width) && ($height == $this->height)))
            return true;
        if (!$width || (($height / $width) < ($this->height / $this->width)))
            $width = intval(($this->width * $height) / $this->height);
        elseif (!$height || (($width / $height) < ($this->width / $this->height)))
            $height = intval(($this->height * $width) / $this->width);
        if (!$width) $width = 1;
        if (!$height) $height = 1;
        return $this->resize($width, $height);
    }
491846
public static function image_widthin($src, $dest, $w, $h) {
        $img = getimagesize(WEB_ROOT . $src);
        if (!$img) {
            return false;
        }
        $nw = $img[0];
        $nh = $img[1];
        if ($nw > $w && $w > 0) {
            $nh = (($w / $nw) * $nh);
            $nw = $w;
        }
        if ($nh > $h && $h > 0) {
            $nw = (($h / $nh) * $nw);
            $nh = $h;
        }
        if ($nw != $img[0] || $nh != $img[1]) {
            self::image_resize(WEB_ROOT . $src, WEB_ROOT . $dest, $nw, $nh);
        } else {
            copy(WEB_ROOT . $src, WEB_ROOT . $dest);
        }
        return $dest;
    }
1327471
public function getConstrainedDimensions($curW, $curH, $maxW, $maxH)
	{
	    $this->debug->groupCollapsed(__METHOD__);
	    $ratio = $curW / $curH;   // > 1 = wider than tall (landscape) < 1 = portrait
	    $return = array('w' => $curW, 'h' => $curH);
	    if ($return['w'] > $maxW) {
	        $this->debug->log('fitting to maxW');
	        $return = array(
	            'w' => $maxW,
	            'h' => round($maxW / $ratio)
	        );
	    }
	    if ($return['h'] > $maxH) {
	        $this->debug->log('fitting to maxH');
	        $return = array(
	            'w' => round($maxH * $ratio),
	            'h' => $maxH
	        );
	    }
	    // $this->debug->log('return', $return);
	    $this->debug->groupEnd();
	    return $return;
	}
445490
public function expandTo($width, $height=null)
    {
        $size = $width instanceof Size ? $width : new static($width, $height);

        if (!$size->isValid()) {
            return $this->scaleTo($size);
        }

        $myAspectRatio = $this->aspectRatio();

        $newWidth = $size->height() * $myAspectRatio;

        if ($newWidth >= $size->width()) {
            return new static($newWidth, $size->height());
        }

        return new static($size->width(), $size->width() / $myAspectRatio);
    }
884104
public function getDimension($w, $h) {
        $labels = $this->getBiggestLabels(false);
        $pixelsAround = array(0, 0, 0, 0); // TRBL
        if (isset($labels[CINLabel::POSITION_TOP])) {
            $dimension = $labels[CINLabel::POSITION_TOP]->getDimension();
            $pixelsAround[0] += $dimension[1];
        }

        if (isset($labels[CINLabel::POSITION_RIGHT])) {
            $dimension = $labels[CINLabel::POSITION_RIGHT]->getDimension();
            $pixelsAround[1] += $dimension[0];
        }

        if (isset($labels[CINLabel::POSITION_BOTTOM])) {
            $dimension = $labels[CINLabel::POSITION_BOTTOM]->getDimension();
            $pixelsAround[2] += $dimension[1];
        }

        if (isset($labels[CINLabel::POSITION_LEFT])) {
            $dimension = $labels[CINLabel::POSITION_LEFT]->getDimension();
            $pixelsAround[3] += $dimension[0];
        }

        $finalW = ($w + $this->offsetX) * $this->scale;
        $finalH = ($h + $this->offsetY) * $this->scale;

        // This section will check if a top/bottom label is too big for its width and left/right too big for its height
        $reversedLabels = $this->getBiggestLabels(true);
        foreach ($reversedLabels as $label) {
            $dimension = $label->getDimension();
            $alignment = $label->getAlignment();
            if ($label->getPosition() === CINLabel::POSITION_LEFT || $label->getPosition() === CINLabel::POSITION_RIGHT) {
                if ($alignment === CINLabel::ALIGN_TOP) {
                    $pixelsAround[2] = max($pixelsAround[2], $dimension[1] - $finalH);
                } elseif ($alignment === CINLabel::ALIGN_CENTER) {
                    $temp = ceil(($dimension[1] - $finalH) / 2);
                    $pixelsAround[0] = max($pixelsAround[0], $temp);
                    $pixelsAround[2] = max($pixelsAround[2], $temp);
                } elseif ($alignment === CINLabel::ALIGN_BOTTOM) {
                    $pixelsAround[0] = max($pixelsAround[0], $dimension[1] - $finalH);
                }
            } else {
                if ($alignment === CINLabel::ALIGN_LEFT) {
                    $pixelsAround[1] = max($pixelsAround[1], $dimension[0] - $finalW);
                } elseif ($alignment === CINLabel::ALIGN_CENTER) {
                    $temp = ceil(($dimension[0] - $finalW) / 2);
                    $pixelsAround[1] = max($pixelsAround[1], $temp);
                    $pixelsAround[3] = max($pixelsAround[3], $temp);
                } elseif ($alignment === CINLabel::ALIGN_RIGHT) {
                    $pixelsAround[3] = max($pixelsAround[3], $dimension[0] - $finalW);
                }
            }
        }

        $this->pushLabel[0] = $pixelsAround[3];
        $this->pushLabel[1] = $pixelsAround[0];

        $finalW = ($w + $this->offsetX) * $this->scale + $pixelsAround[1] + $pixelsAround[3];
        $finalH = ($h + $this->offsetY) * $this->scale + $pixelsAround[0] + $pixelsAround[2];

        return array($finalW, $finalH);
    }
758401
private function get_size_by_fit($new_width, $new_height)
    {
        $height_ratio = $this->height / $new_height;
        $width_ratio  = $this->width /  $new_width;

        $max = max($height_ratio, $width_ratio);

        return array(
            'optimal_width'  => $this->width / $max,
            'optimal_height' => $this->height / $max,
        );
    }
370659
function(w, h) {
    grids[0].set( space.size.$multiply( 0.1 ) ).to( space.size.$multiply( 0.9, 0.3 ) ).init( 50, 50, "fix", "fix" );
    grids[1].set( space.size.$multiply( 0.1, 0.4 ) ).to( space.size.$multiply( 0.9, 0.6 ) ).init( 50, 50, "flex", "flex" );
    grids[2].set( space.size.$multiply( 0.1, 0.7 ) ).to( space.size.$multiply( 0.9, 0.9 ) ).init( 5, 8, "stretch", "stretch" );
  }
1008906
protected function getNewHeight($width, $height) 
    {
        if ($height > 0) {
            return $height;
        }
        
        // original width : new width = original height : X
        return $width * $this->imageInfo['height'] / $this->imageInfo['width'];
    }
1279537
public function divide($width, $height=null)
    {
        if ($width instanceof Size) {
            $height = $width->height();
            $width = $width->width();
        }

        $height = $height ? $height : $width;

        return new static($this->width()/$width, $this->height()/$height);
    }
519296
public function filled_rectangle($x1, $y1, $w, $h, $color)
    {
        // Scale by the AA factor and DPI
        $x1 = $this->_upscale($x1);
        $y1 = $this->_upscale($y1);
        $w = $this->_upscale($w);
        $h = $this->_upscale($h);

        $c = $this->_allocate_color($color);

        imagefilledrectangle($this->get_image(), $x1, $y1, $x1 + $w, $y1 + $h, $c);
    }
723659
public function crop($w, $h, $x = 0, $y = 0, $width = null, $height = null){
        $this->img->crop($w, $h, $x, $y, $width, $height);
        return $this;
    }
590408
public void setBounds(int x, int y, int w, int h) {

        super.setBounds(x, y, w, h);

        iSbHeight = sbHoriz.getPreferredSize().height;
        iSbWidth  = sbVert.getPreferredSize().width;
        iHeight   = h - iSbHeight;
        iWidth    = w - iSbWidth;

        sbHoriz.setBounds(0, iHeight, iWidth, iSbHeight);
        sbVert.setBounds(iWidth, 0, iSbWidth, iHeight);
        adjustScroll();

        iImage = null;

        repaint();
    }