Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Watermark and padding
  • I would like to put a watermark on my thumbnails.
    It looks work fine with the $position argument, but with the $padding argument seems weird to me.
    We can't put a top-padding and a différent left-padding for exemple.
    Do you think it's a good idea to update the code like :
    /**
    * Executes the watermark event when the queue is ran.
    * Formats the watermark method input for use with driver specific methods
    * @param   string   $filename  The filename of the watermark file to use.
    * @param   string   $position  The position of the watermark, ex: "bottom right", "center center", "top left"
    * @param   string  $padding The amount of padding (in pixels) from the position. ex "10 5", "-10 5", "5"
    * @return  array An array of variables for the specific driver.
    */
    protected function _watermark($filename, $position, $padding = '5 5')
    {
     $filename = realpath($filename);
     $return = false;
     if (is_file($filename) and $this->check_extension($filename, false))
     {
      $x = 0;
      $y = 0;
      $wsizes = $this->sizes($filename);
      $sizes  = $this->sizes();
      list($ypos, $xpos) = explode(' ', $position);
      list($ypadding, $xpadding) = explode(' ', $padding);
      $xpadding = empty($xpadding) ? $ypadding : $xpadding;
      switch ($xpos)
      {
       case 'left':
        $x = $xpadding;
       break;
       case 'middle':
       case 'center':
        $x = ($sizes->width / 2) - ($wsizes->width / 2) + $xpadding;
       break;
       case 'right':
        $x = $sizes->width - $wsizes->width - $xpadding;
       break;
      }
      switch ($ypos)
      {
       case 'top':
        $y = $ypadding;
       break;
       case 'middle':
       case 'center':
        $y = ($sizes->height / 2) - ($wsizes->height / 2) + $ypadding;
       break;
       case 'bottom':
        $y = $sizes->height - $wsizes->height - $ypadding;
       break;
      }
      $this->debug("Watermark being placed at $x,$y");
      $return = array(
       'filename' => $filename,
       'x' => $x,
       'y' => $y,
       'padding' => $padding,
      );
     }
     return $return;
    }
  • The purpose is to have the choice of the vertical et horizontal padding 
  • HarroHarro
    Accepted Answer
    I understand. You're making my todo list longer and longer... ;-)
  • I'm sorry ...
  • Padding is defined in pixels, so it's a number. And padding happens depending on the defined position.

    If you define "center", no padding happens at all, because center is center. You can't use padding to define an "offset" from the center. If you define "left", padding is used as a defined left offset, if you define "right", it's used as a defined right offset.

    So if you define "left center" and 5, the watermark is positions vertical center, 5 pixels from the left.

    Multiple padding values doesn't really make sense, if you position the watermark left, any right padding is useless. But indeed, if you position "top left", the padding top and left will be the same.

    I think it would also be handy to be able to define "10 50" as a position, so hardcode the location, which at the moment isn't possible either.
  • HarroHarro
    Accepted Answer
    Just committed both features.

    You can define different padding for top/bottom and left/right by passing something like array(10,20) for the padding.
  • Great ! it's cool. Thanks

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion