public function best_fit($max_width, $max_height, $upscale = false) { if ($upscale === false && ($width >= $this->image_class->get_width() || $height >= $this->image_class->get_height())) { return $this; } $this->image_class->best_fit($max_width, $max_height); return $this; }
/** * @return SimpleImage */ protected function create() { $image = new SimpleImage($this->file); switch ($this->options['strategy']) { case 'thumbnail': $width = $this->options['w'] ?: $image->get_width(); $height = $this->options['h'] ?: $image->get_height(); $image->resize($width, $height); break; case 'best_fit': $width = $this->options['w'] ?: $image->get_width(); $height = $this->options['h'] ?: $image->get_height(); if (is_numeric($width) && is_numeric($height)) { $image->best_fit($width, $height); } break; default: $width = $this->options['w']; $height = $this->options['h']; if (is_numeric($width) && is_numeric($height)) { $image->thumbnail($width, $height); } elseif (is_numeric($width)) { $image->fit_to_width($width); } elseif (is_numeric($height)) { $image->fit_to_height($height); } else { $width = $image->get_width(); $height = $image->get_height(); $image->thumbnail($width, $height); } } return $image; }
<?php namespace abeautifulsite; use Exception; require 'src/abeautifulsite/SimpleImage.php'; $image = new SimpleImage("../images/post.jpg"); $archivo = $_GET['image']; $image2 = new SimpleImage("uploads/" . $archivo); $image2->best_fit(300, 300)->save('uploads/tmp_' . $archivo); /* $a_texto = explode(' ', $texto); $tmp_text = ""; if(strlen($texto) > 100){ 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);
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 { } } } }
/** * @return SimpleImage */ protected function create() { $image = new SimpleImage($this->file); $width = $this->options['w'] ?: $image->get_width(); $height = $this->options['h'] ?: $image->get_height(); switch ($this->options['strategy']) { case 'thumbnail': $image->resize($width, $height); break; case 'best_fit': $image->best_fit($width, $height); break; default: $image->thumbnail($width, $height); } return $image; }