Beispiel #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();
         }
     }
 }
 /**
  * Remove EXIF data if needed
  *
  * @param $file
  * @return bool
  * @throws Exception
  */
 private static function removeExif($file)
 {
     if ($exif = @read_exif_data($file)) {
         if (!empty($exif['Orientation'])) {
             $img = new SimpleImage($file);
             if ($img->save()) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return true;
         }
     } else {
         return false;
     }
 }
Beispiel #3
0
    $pozY = $posy;
    $marX = $wmpadx;
    $marY = $wmpady;
    $widMain = $imagewidth;
    $heigMain = $imageheight;
    $widWat = $wtwidth;
    $heigWat = $wtheight;
    $img = new SimpleImage($img_main_path);
    $newPozX = $pozX;
    while ($newPozX < $widMain) {
        $newPozY = $pozY;
        while ($newPozY < $heigMain) {
            $img->overlay($img_watmark_path, 'top left', $opacity, $newPozX, $newPozY);
            $newPozY += $heigWat + $marX;
        }
        $newPozX += $widWat + $marY;
    }
    $img->save('../loadimg/' . $result_filename);
}
$uploadpath = "../loadimg/result.jpg";
exit($uploadpath);
/*$answer['1'] = $$img_watmark_path;
$answer['2'] = $imageheight;
$answer['3'] = $wtwidth;
$answer['4'] = $wtheight;
$answer['pathimg'] = $img_main_path;



header("Content-Type: application/json");
echo json_encode($answer);*/
Beispiel #4
0
<?php

namespace abeautifulsite;

use Exception;
require '../src/abeautifulsite/SimpleImage.php';
if (!is_dir('processed/')) {
    mkdir('processed/');
}
try {
    // Create an image from scratch
    $img = new SimpleImage(null, 500, 200, '#FFCC00');
    $img->text('Dynamically Created Image', 'delicious.ttf');
    $img->save('processed/created-image.png');
    // If you use create function instead of loading image
    // you have to define output extension
    $img->output('png');
} catch (Exception $e) {
    echo '<span style="color: red;">' . $e->getMessage() . '</span>';
}
 public function save($filename = null, $quality = null, $format = null)
 {
     $this->image_class->save($filename, $quality, $format);
 }
 /**
  * @param string $source
  * @param array $options
  * @return bool|mixed
  */
 protected function resizeImage($source, $options)
 {
     try {
         $cachepath = $this->getCachePath($source, $options);
         if (!file_exists($cachepath)) {
             $image = new SimpleImage(App::path() . '/' . $source);
             if (!empty($options['width']) && empty($options['height'])) {
                 $image->fit_to_width($options['width']);
             }
             if (!empty($options['height']) && empty($options['width'])) {
                 $image->fit_to_height($options['height']);
             }
             if (!empty($options['height']) && !empty($options['width'])) {
                 $image->thumbnail($options['width'], $options['height']);
             }
             $image->save($cachepath);
         }
         return trim(str_replace(App::path(), '', $cachepath), '/');
     } catch (\Exception $e) {
         return false;
     }
 }
Beispiel #7
0
 protected function handle_image($data)
 {
     $image = null;
     if (request()->has('delete_image')) {
         $fullpath = public_path() . '/uploads/' . $image->image;
         @unlink($fullpath);
         $fullpath = null;
     }
     if (request()->hasFile('image')) {
         $image = request()->file('image');
         if ($image->isValid()) {
             $valid_ext = ['jpg', 'jpeg', 'gif', 'png', 'bmp'];
             $ext = $image->getClientOriginalExtension();
             if (in_array($ext, $valid_ext)) {
                 $fullpath = public_path() . '/uploads/' . $image->getClientOriginalName();
                 $target = $image->move(public_path() . '/uploads', $image->getClientOriginalName());
                 # RESIZE
                 if (file_exists($fullpath)) {
                     $newpath = public_path() . '/uploads/faq_' . $data->id . '.' . $ext;
                     if (file_exists($newpath)) {
                         @unlink($newpath);
                     }
                     $resize = new SimpleImage($fullpath);
                     $resize->best_fit(100, 100);
                     $resize->save($newpath);
                     @unlink($fullpath);
                     # SAVE IMAGE FILENAME
                     $data->image = 'faq_' . $data->id . '.' . $ext;
                     $data->save();
                 }
             } else {
             }
         }
     }
 }
	if(strlen($texto) > 150){
		$y = 10;
	}
	else{
		$y = 2;
	}
}
else {
	$y = 1;
}

foreach ($a_texto as $txt) {
	if(strlen($txt)+strlen($tmp_text) < 35) {
		$tmp_text .= ' '.$txt;		
	} else{
		$image->text($tmp_text, 'font.ttf', 15, '#4D4D4D', 'center', 200, $y);
		$y=$y+35;
		$tmp_text = $txt;
		//$image->text($txt, 'font.ttf', 20, '#4D4D4D', 'center', 0, $y);
	}

}
if($texto <= 35) {
	$image->text($tmp_text, 'font.ttf', 15, '#4D4D4D', 'center', 200, $y);

}
*/
$image->overlay('uploads/tmp_' . $archivo, 'center center', 1, 20, 0);
echo $file_name = rand(0, 10000) . '-' . rand(0, 10000) . '-' . rand(0, 10000) . '.jpg';
$image->save('posts/' . $file_name);
 /**
  * @param string $source
  * @param array $options
  * @return bool|mixed
  */
 protected function resizeImage($source, $options)
 {
     try {
         $image_path = App::locator()->get($source);
         $cachepath = $this->getCachePath($image_path, $options);
         if (!file_exists($cachepath)) {
             $image = new SimpleImage($image_path);
             if (!empty($options['width']) && empty($options['height'])) {
                 $image->fit_to_width($options['width']);
             }
             if (!empty($options['height']) && empty($options['width'])) {
                 $image->fit_to_height($options['height']);
             }
             if (!empty($options['height']) && !empty($options['width'])) {
                 $image->thumbnail($options['width'], $options['height']);
             }
             $image->save($cachepath);
         }
         return $this->basePath($cachepath);
     } catch (\Exception $e) {
         return false;
     }
 }
Beispiel #10
0
 /**
  * Reduce image size and optimize the image quality
  *
  * @author salvipascual
  * @author kuma
  * @version 2.0
  * @param String $imagePath, path to the image
  * @param number $width Fit to width
  * @param number $height Fit to height
  * @param number $quality Decrease/increase quality
  * @param string $format Convert to format
  * @return boolean
  */
 public function optimizeImage($imagePath, $width = "", $height = "", $quality = 70, $format = 'image/jpeg')
 {
     if (!class_exists('SimpleImage')) {
         include_once "../lib/SimpleImage.php";
     }
     try {
         $img = new SimpleImage();
         $img->load($imagePath);
         if (!empty($width)) {
             $img->fit_to_width($width);
         }
         if (!empty($height)) {
             $img->fit_to_height($height);
         }
         $img->save($imagePath, $quality, $format);
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
        $img->save('./file/watermarked.jpg');
    } else {
        if ($mode == "tile") {
            $pozX = $originX;
            $pozY = $originY;
            $marX = $marginX;
            $marY = $marginY;
            $widMain = $imagewidth;
            $heigMain = $imageheight;
            $widWat = $wtwidth;
            $heigWat = $wtheight;
            $img = new SimpleImage($uploadfile);
            $newPozX = $pozX;
            while ($newPozX < $widMain) {
                $newPozY = $pozY;
                while ($newPozY < $heigMain) {
                    $img->overlay($watermarkfile, 'top left', $opacity, $newPozX, $newPozY);
                    $newPozY += $heigWat + $marX;
                }
                $newPozX += $widWat + $marY;
            }
            $img->save('./file/watermarked.jpg');
        }
    }
}
// else {
// 	echo "<h3>Ошибка! Не удалось загрузить файл на сервер!</h3>";
// 	exit;
// }
header("Content-Type: application/json");
echo json_encode($answer);