Exemple #1
0
 /**
  *  Resizes the image.
  *
  *  @param array $options = [
  *                  'type' => 'resizemin|resizecrop|resize|crop|reduce',
  *                  'size' => ['x' => 2000, 'y' => 500]
  *               ]
  *               You can also set the size without specifying x and y:
  *               [2000, 500]. Or directly 'size' => 2000 (takes 2000x2000)
  *  @return bool true on success; otherwise false
  */
 public function resize($options = [])
 {
     try {
         $this->image->resize($options['type'], $options['size']);
         return true;
     } catch (Exception $e) {
         array_push($this->errors, $e->getMessage());
         return false;
     }
 }
Exemple #2
0
<?php

require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config.php';
use Elboletaire\Watimage\Image;
$image_file = FILES . 'peke.jpg';
$orientate = FILES . 'tripi.jpg';
/*********************
 *** RESIZE IMAGES ***
 *********************/
$image = new Image($image_file);
// allowed types: resize [or classic], reduce, min [or resizemin], crop and resizecrop
$image->resize('resizecrop', 400, 200)->generate(OUTPUT . 'image1-resizecrop.jpg');
/*********************
 *** ROTATE IMAGES ***
 *********************/
$image = new Image($image_file);
// check out Normalize::color to see all the allowed possibilities about how
// to set colors. Angle must be specified in degrees (positive is clockwise)
$image->rotate(90, '#fff')->generate(OUTPUT . 'image2-rotate.jpg');
// Images are automatically orientated by default when using the constructor
// instead of load. You can skip it and you can also auto-orientate images later:
// disable auto-orientate on load
$image = new Image($orientate, false);
// we can later use the autoOrientate method if we not did it previously:
$image->autoOrientate()->generate(OUTPUT . 'image3-auto-orientate.jpg');
/**********************************
 *** EXPORTING TO OTHER FORMATS ***
 **********************************/
$image = new Image($image_file);
$image->generate(OUTPUT . 'image4-formats.png', 'image/png');
/*******************