Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Studio107/Mindy_Orm
Browse files Browse the repository at this point in the history
  • Loading branch information
Falaleev Maxim committed Apr 21, 2015
2 parents 3481420 + 3ba4a06 commit 44dfbc5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Mindy/Orm/Fields/ImageField.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ImageField extends FileField
*
* position can be array [x,y] coordinates or
* string with one of available position
* top, top-left, top-right, bottom, bottom-left, bottom-right, left, right, center
* top, top-left, top-right, bottom, bottom-left, bottom-right, left, right, center, repeat
*/
public $watermark = null;
/**
Expand Down
12 changes: 10 additions & 2 deletions src/Mindy/Orm/Fields/ManyToManyField.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ public function getRelatedModelColumn()
{
if (!$this->_relatedModelColumn) {
$cls = $this->modelClass;
$end = $this->getRelatedModelPk();
if ($cls == $this->ownerClassName) {
$end = 'to';
}
$tmp = explode('\\', $cls);
$column = $cls::normalizeTableName(end($tmp));
$this->_relatedModelColumn = $column . '_' . $this->getRelatedModelPk();
$this->_relatedModelColumn = $column . '_' . $end;
}
return $this->_relatedModelColumn;
}
Expand All @@ -129,9 +133,13 @@ public function getModelColumn()
{
if (!$this->_modelColumn) {
$cls = $this->ownerClassName;
$end = $this->getModelPk();
if ($cls == $this->modelClass) {
$end = 'from';
}
$tmp = explode('\\', $cls);
$column = $cls::normalizeTableName(end($tmp));
$this->_modelColumn = $column . '_' . $this->getModelPk();
$this->_modelColumn = $column . '_' . $end;
}
return $this->_modelColumn;
}
Expand Down
36 changes: 34 additions & 2 deletions src/Mindy/Orm/Traits/ImageProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public function applyWatermark($source, $options)
$sWidth = $sSize->getWidth();
$sHeight = $sSize->getHeight();

$repeat = false;

if (is_array($position)) {
list($x, $y) = $position;
} else {
Expand Down Expand Up @@ -182,6 +184,9 @@ public function applyWatermark($source, $options)
$x = $sWidth - $wWidth;
$y = $sHeight - $wHeight;
break;
case 'repeat':
$repeat = true;
break;
}
if ($x < 0) {
$x = 0;
Expand All @@ -190,8 +195,35 @@ public function applyWatermark($source, $options)
$y = 0;
}
}
if (($x + $wWidth <= $sWidth) && ($y + $wHeight <= $sHeight))
return $source->paste($watermark, new Point($x, $y));

if ($repeat) {
while($y < $sHeight) {
$appendY = $wHeight;
if ($y + $appendY > $sHeight) {
$appendY = $sHeight - $y;
}
$x = 0;
while ($x < $sWidth) {
$appendX = $wWidth;
if ($x + $appendX > $sWidth) {
$appendX = $sWidth - $x;
}

if ($appendY != $wHeight || $appendX != $wWidth) {
$source->paste($watermark->copy()->crop(new Point(0, 0), new Box($appendX, $appendY)),
new Point($x, $y));
} else {
$source->paste($watermark, new Point($x, $y));
}

$x += $appendX;
}
$y += $appendY;
}
} else {
if (($x + $wWidth <= $sWidth) && ($y + $wHeight <= $sHeight))
return $source->paste($watermark, new Point($x, $y));
}
}
return $source;
}
Expand Down

0 comments on commit 44dfbc5

Please sign in to comment.