Exemplo n.º 1
0
 public function upload_image($image, $properties)
 {
     // Filename
     $random_string = $properties['filename'] . '-' . str_replace(' ', '_', $image['name']);
     // Initialise SimpleImage
     $img = new SimpleImage($image['tmp_name']);
     // Get Properties
     $max_width = $properties['max_width'];
     // Check for min width
     if (isset($properties['min_width'])) {
         if ($img->get_width() < $properties['min_width']) {
             return false;
         }
     }
     // Resize image
     try {
         $img->fit_to_width($max_width);
         $img->save($this->upload_folder . '/' . $random_string);
         // Save the image to the_image
         $this->the_image = $this->public_folder . '/' . $random_string;
     } catch (Exception $e) {
         echo $e->getMessage();
         // In a production app, the error should be logged or
         // sent to your own error handler/alert system and not
         // echoed out.
     }
     // Check to see if we need to generate thumbnail
     if (isset($properties['thumbnail'])) {
         // Get Properties
         $thumb_width = $properties['thumbnail']['width'];
         $thumb_height = $properties['thumbnail']['height'];
         // Generate thumbnail
         try {
             $img->adaptive_resize($thumb_width, $thumb_height);
             $img->save($this->upload_folder . '/thumbnails/' . $random_string);
             // Save the image to the_thumbnail
             $this->the_thumbnail = $this->public_folder . '/thumbnails/' . $random_string;
         } catch (Exception $e) {
             echo $e->getMessage();
         }
     }
 }
Exemplo n.º 2
0
<?php

namespace abeautifulsite;

use Exception;
require 'src/abeautifulsite/SimpleImage.php';
$image = new SimpleImage("../images/post.png");
$image->adaptive_resize(300, 300)->auto_orient()->save("prueba.png");