Skip to content

Fixing misspeled "percent" unit in `pasteImage()` #9

Merged
merged 3 commits into from Nov 20, 2012
View
124 src/PHPImageWorkshop/ImageWorkshop.php
@@ -80,6 +80,16 @@ class ImageWorkshop
* Background Image
*/
protected $image;
+
+ /**
+ * @var string
+ */
+ const UNIT_PIXEL = 'pixel';
+
+ /**
+ * @var string
+ */
+ const UNIT_PERCENT = 'percent';
/**
* @var integer
@@ -242,14 +252,14 @@ public function __clone()
* You can specify the position left (in pixels) and the position top (in pixels) of the added image relatives to the layer
* Otherwise, it will be set at 0 and 0
*
- * @param string $unit
+ * @param string $unit Use one of `UNIT_*` constants, "UNIT_PIXEL" by default
* @param resource $image
* @param integer $positionX
* @param integer $positionY
*/
- public function pasteImage($unit = "pixel", $image, $positionX = 0, $positionY = 0)
+ public function pasteImage($unit = self::UNIT_PIXEL, $image, $positionX = 0, $positionY = 0)
{
- if ($unit == "pourcent") {
+ if ($unit == self::UNIT_PERCENT) {
$positionX = round(($positionX / 100) * $this->width);
$positionY = round(($positionY / 100) * $this->height);
@@ -733,10 +743,10 @@ public function resizeInPixel($newWidth = null, $newHeight = null, $converseProp
}
/**
- * Resize the layer by specifying a pourcent
+ * Resize the layer by specifying a percent
*
- * @param float $pourcentWidth
- * @param float $pourcentHeight
+ * @param float $percentWidth
+ * @param float $percentHeight
* @param boolean $converseProportion
* @param integer $positionX
* @param integer $positionY
@@ -746,17 +756,17 @@ public function resizeInPixel($newWidth = null, $newHeight = null, $converseProp
*
* $positionX, $positionY, $position can be ignored unless you choose a new width AND a new height AND to conserve proportion.
*/
- public function resizeInPourcent($pourcentWidth = null, $pourcentHeight = null, $converseProportion = false, $positionX = 0, $positionY = 0, $position = 'MM')
+ public function resizeInPercent($percentWidth = null, $percentHeight = null, $converseProportion = false, $positionX = 0, $positionY = 0, $position = 'MM')
{
- $this->resize('pourcent', $pourcentWidth, $pourcentHeight, $converseProportion, $positionX, $positionY, $position);
+ $this->resize(self::UNIT_PERCENT, $percentWidth, $percentHeight, $converseProportion, $positionX, $positionY, $position);
}
/**
* Resize the layer
*
- * @param string $unit
- * @param float $pourcentWidth
- * @param float $pourcentHeight
+ * @param string $unit Use one of `UNIT_*` constants, "UNIT_PIXEL" by default
+ * @param float $percentWidth
+ * @param float $percentHeight
* @param boolean $converseProportion
* @param integer $positionX
* @param integer $positionY
@@ -766,11 +776,11 @@ public function resizeInPourcent($pourcentWidth = null, $pourcentHeight = null,
*
* $positionX, $positionY, $position can be ignored unless you choose a new width AND a new height AND to conserve proportion.
*/
- public function resize($unit = "pixel", $newWidth = null, $newHeight = null, $converseProportion = false, $positionX = 0, $positionY = 0, $position = 'MM')
+ public function resize($unit = self::UNIT_PIXEL, $newWidth = null, $newHeight = null, $converseProportion = false, $positionX = 0, $positionY = 0, $position = 'MM')
{
if ($newWidth || $newHeight) {
- if ($unit == 'pourcent') {
+ if ($unit == self::UNIT_PERCENT) {
if ($newWidth) {
@@ -832,49 +842,49 @@ public function resize($unit = "pixel", $newWidth = null, $newHeight = null, $co
} elseif ($newWidth) {
- $widthResizePourcent = $newWidth / ($this->width / 100);
+ $widthResizePercent = $newWidth / ($this->width / 100);
- $newHeight = round(($widthResizePourcent / 100) * $this->height);
- $heightResizePourcent = $widthResizePourcent;
+ $newHeight = round(($widthResizePercent / 100) * $this->height);
+ $heightResizePercent = $widthResizePercent;
} elseif ($newHeight) {
- $heightResizePourcent = $newHeight / ($this->height / 100);
+ $heightResizePercent = $newHeight / ($this->height / 100);
- $newWidth = round(($heightResizePourcent / 100) * $this->width);
- $widthResizePourcent = $heightResizePourcent;
+ $newWidth = round(($heightResizePercent / 100) * $this->width);
+ $widthResizePercent = $heightResizePercent;
}
} elseif (($newWidth && !$newHeight) || (!$newWidth && $newHeight)) { // New width OR new height is given
if ($newWidth) {
- $widthResizePourcent = $newWidth / ($this->width / 100);
+ $widthResizePercent = $newWidth / ($this->width / 100);
- $heightResizePourcent = 100;
+ $heightResizePercent = 100;
$newHeight = $this->height;
} else {
- $heightResizePourcent = $newHeight / ($this->height / 100);
+ $heightResizePercent = $newHeight / ($this->height / 100);
- $widthResizePourcent = 100;
+ $widthResizePercent = 100;
$newWidth = $this->width;
}
} else { // New width AND new height are given
- $widthResizePourcent = $newWidth / ($this->width / 100);
+ $widthResizePercent = $newWidth / ($this->width / 100);
- $heightResizePourcent = $newHeight / ($this->height / 100);
+ $heightResizePercent = $newHeight / ($this->height / 100);
}
// Update the layer positions in the stack
foreach ($this->layerPositions as $layerId => $layerPosition) {
- $newPosX = round(($widthResizePourcent / 100) * $layerPosition['x']);
- $newPosY = round(($heightResizePourcent / 100) * $layerPosition['y']);
+ $newPosX = round(($widthResizePercent / 100) * $layerPosition['x']);
+ $newPosY = round(($heightResizePercent / 100) * $layerPosition['y']);
$this->changePosition($layerId, $newPosX, $newPosY);
}
@@ -885,7 +895,7 @@ public function resize($unit = "pixel", $newWidth = null, $newHeight = null, $co
foreach ($layers as $key => $layer) {
- $layer->resizeInPourcent($widthResizePourcent, $heightResizePourcent);
+ $layer->resizeInPercent($widthResizePercent, $heightResizePercent);
$this->layers[$key] = $layer;
}
@@ -907,26 +917,26 @@ public function resizeByLargestSideInPixel($newLargestSideWidth, $conversePropor
}
/**
- * Resize the layer by its largest side by specifying pourcent
+ * Resize the layer by its largest side by specifying percent
*
- * @param integer $newLargestSideWidth pourcent
+ * @param integer $newLargestSideWidth percent
* @param boolean $converseProportion
*/
- public function resizeByLargestSideInPourcent($newLargestSideWidth, $converseProportion = false)
+ public function resizeByLargestSideInPercent($newLargestSideWidth, $converseProportion = false)
{
- $this->resizeByLargestSide('pourcent', $newLargestSideWidth, $converseProportion);
+ $this->resizeByLargestSide(self::UNIT_PERCENT, $newLargestSideWidth, $converseProportion);
}
/**
* Resize the layer by its largest side
*
* @param string $unit
- * @param integer $newLargestSideWidth pourcent
+ * @param integer $newLargestSideWidth percent
* @param boolean $converseProportion
*/
- public function resizeByLargestSide($unit = "pixel", $newLargestSideWidth, $converseProportion = false)
+ public function resizeByLargestSide($unit = self::UNIT_PIXEL, $newLargestSideWidth, $converseProportion = false)
{
- if ($unit == 'pourcent') {
+ if ($unit == self::UNIT_PERCENT) {
$newLargestSideWidth = round(($newLargestSideWidth / 100) * $this->getLargestSideWidth());
}
@@ -953,14 +963,14 @@ public function resizeByNarrowSideInPixel($newNarrowSideWidth, $converseProporti
}
/**
- * Resize the layer by its narrow side by specifying pourcent
+ * Resize the layer by its narrow side by specifying percent
*
- * @param integer $newNarrowSideWidth pourcent
+ * @param integer $newNarrowSideWidth percent
* @param boolean $converseProportion
*/
- public function resizeByNarrowSideInPourcent($newNarrowSideWidth, $converseProportion = false)
+ public function resizeByNarrowSideInPercent($newNarrowSideWidth, $converseProportion = false)
{
- $this->resizeByNarrowSide('pourcent', $newNarrowSideWidth, $converseProportion);
+ $this->resizeByNarrowSide(self::UNIT_PERCENT, $newNarrowSideWidth, $converseProportion);
}
/**
@@ -972,7 +982,7 @@ public function resizeByNarrowSideInPourcent($newNarrowSideWidth, $conversePropo
*/
public function resizeByNarrowSide($unit = "pixel", $newNarrowSideWidth, $converseProportion = false)
{
- if ($unit == 'pourcent') {
+ if ($unit == self::UNIT_PERCENT) {
$newNarrowSideWidth = round(($newNarrowSideWidth / 100) * $this->getNarrowSideWidth());
}
@@ -1006,21 +1016,21 @@ public function cropInPixel($width = 0, $height = 0, $positionX = 0, $positionY
}
/**
- * Crop the document by specifying pourcent
+ * Crop the document by specifying percent
*
* $backgroundColor can be set transparent (but script could be long to execute)
* $position: http://phpimageworkshop.com/doc/22/corners-positions-schema-of-an-image.html
*
- * @param float $pourcentWidth
- * @param float $pourcentHeight
- * @param float $positionXPourcent
- * @param float $positionYPourcent
+ * @param float $percentWidth
+ * @param float $percentHeight
+ * @param float $positionXPercent
+ * @param float $positionYPercent
* @param string $position
* @param string $backgroundColor
*/
- public function cropInPourcent($pourcentWidth = 0, $pourcentHeight = 0, $positionXPourcent = 0, $positionYPourcent = 0, $position = "LT", $backgroundColor = "ffffff")
+ public function cropInPercent($percentWidth = 0, $percentHeight = 0, $positionXPercent = 0, $positionYPercent = 0, $position = "LT", $backgroundColor = "ffffff")
{
- $this->crop("pourcent", $pourcentWidth, $pourcentHeight, $positionXPourcent, $positionYPourcent, $position, $backgroundColor);
+ $this->crop(self::UNIT_PERCENT, $percentWidth, $percentHeight, $positionXPercent, $positionYPercent, $position, $backgroundColor);
}
/**
@@ -1029,17 +1039,17 @@ public function cropInPourcent($pourcentWidth = 0, $pourcentHeight = 0, $positio
* $backgroundColor can be set transparent (but script could be long to execute)
* $position: http://phpimageworkshop.com/doc/22/corners-positions-schema-of-an-image.html
*
- * @param string $unit
+ * @param string $unit Use one of `UNIT_*` constants, "UNIT_PIXEL" by default
* @param float $width
* @param float $height
* @param float $positionX
* @param float $positionY
* @param string $position
* @param string $backgroundColor
*/
- public function crop($unit = "pixel", $width = 0, $height = 0, $positionX = 0, $positionY = 0, $position = "LT", $backgroundColor = "ffffff")
+ public function crop($unit = self::UNIT_PIXEL, $width = 0, $height = 0, $positionX = 0, $positionY = 0, $position = "LT", $backgroundColor = "ffffff")
{
- if ($unit == "pourcent") {
+ if ($unit == self::UNIT_PERCENT) {
$width = round(($width / 100) * $this->width);
$height = round(($height / 100) * $this->height);
@@ -1096,25 +1106,25 @@ public function crop($unit = "pixel", $width = 0, $height = 0, $positionX = 0, $
*/
public function cropMaximumInPixel($positionX = 0, $positionY = 0, $position = "LT", $backgroundColor = "ffffff")
{
- $this->cropMaximum("pixel", $positionX, $positionY, $position, $backgroundColor);
+ $this->cropMaximum(self::UNIT_PIXEL, $positionX, $positionY, $position, $backgroundColor);
}
/**
- * Crop the maximum possible from left top ("LT"), "RT"... by specifying a shift in pourcent
+ * Crop the maximum possible from left top ("LT"), "RT"... by specifying a shift in percent
*
* $backgroundColor can be set transparent (but script could be long to execute)
* $position: http://phpimageworkshop.com/doc/22/corners-positions-schema-of-an-image.html
*
* @param integer $width
* @param integer $height
- * @param integer $positionXPourcent
- * @param integer $positionYPourcent
+ * @param integer $positionXPercent
+ * @param integer $positionYPercent
* @param string $position
* @param string $backgroundColor
*/
- public function cropMaximumInPourcent($positionXPourcent = 0, $positionYPourcent = 0, $position = "LT", $backgroundColor = "ffffff")
+ public function cropMaximumInPercent($positionXPercent = 0, $positionYPercent = 0, $position = "LT", $backgroundColor = "ffffff")
{
- $this->cropMaximum("pourcent", $positionXPourcent, $positionYPourcent, $position, $backgroundColor);
+ $this->cropMaximum(self::UNIT_PERCENT, $positionXPercent, $positionYPercent, $position, $backgroundColor);
}
/**
@@ -1134,7 +1144,7 @@ public function cropMaximumInPourcent($positionXPourcent = 0, $positionYPourcent
public function cropMaximum($unit = "pixel", $positionX = 0, $positionY = 0, $position = "LT", $backgroundColor = "ffffff")
{
$narrowSide = $this->getNarrowSideWidth();
- if ($unit == "pourcent") {
+ if ($unit == self::UNIT_PERCENT) {
$positionX = round(($positionX / 100) * $this->width);
$positionY = round(($positionY / 100) * $this->height);
Something went wrong with that request. Please try again.