public function __construct($log, $root_dir, $thumbnails_dir) { $this->log = $log; $this->root_dir = $root_dir; $this->thumbnails_dir = $thumbnails_dir; Image::configure(array('driver' => 'imagick')); }
/** * Description * @param object $request * @param string $destino * @return array */ public function cropImage($request, $destino) { $data = $request->all(); if ($request->hasFile('avatar')) { $novoNome = date('d-m-Y-h-i-s') . '-' . $request->file('avatar')->getClientOriginalName(); if ($data['x1'] !== '' && $data['x2'] !== '' && $data['y1'] !== '' && $data['y2'] !== '') { $w = $data['x2'] - $data['x1']; $h = $data['y2'] - $data['y1']; $x = $data['x1']; $y = $data['y1']; Image::configure(array('driver' => 'gd')); $image = Image::make($request->file('avatar')); // width, height, $x, $y $image->crop($w, $h, $x, $y); $image->save($destino . $novoNome); } else { $image = Image::make($request->file('avatar')); $image->save($destino . $novoNome); } $data["avatar"] = $novoNome; } unset($data['_token']); unset($data['x1']); unset($data['y1']); unset($data['x2']); unset($data['y2']); return $data; }
/** * Execute the console command. * * @return mixed */ public function handle() { $in = $this->argument('in'); $out = $this->argument('out'); $size = $this->argument('size'); $dim = explode('x', $this->argument('size')); if (!(ctype_digit($size[0]) && ctype_digit($size[1]))) { $this->line("\nInvalid size argument [ex: ng:resize 200x200 in.png out.png]\n"); exit; } if ($in === $out) { $this->line("\nThe directory in and out path can not be the same.\n"); exit; } if (!is_file($in) && !is_dir($in)) { $this->line("\nInvalid in file or directory argument [ex: ng:resize 200x200 in.png out.png]\n"); exit; } Image::configure(array('driver' => 'imagick')); if (is_file($in)) { $pathinfo = pathinfo($in); if ($out === null) { $out = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '-' . $size . '.' . $pathinfo['extension']; } $img = $this->resize($in, $dim[0], $dim[1], $out); $this->line("\nResizing " . $in . " => " . $out . "\n"); exit; } if (is_dir($in)) { $out = rtrim($out, '/'); $out = rtrim($out, '\\'); if (!is_dir($out)) { mkdir($out); } $files = glob($in . '/*.{jpg,png}', GLOB_BRACE); $this->line(""); foreach ($files as $file) { $pathinfo = pathinfo($file); $img = $this->resize($file, $dim[0], $dim[1], $out . '/' . $pathinfo['basename']); $this->line("Resizing " . $file . " => " . $out . '/' . $pathinfo['basename']); } $this->line(""); exit; } }
require_once __DIR__ . "/../common.php"; function listJpgFiles($root_dir) { $dir = new CallbackFilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root_dir)), function ($current, $key, $iterator) { return substr($current, -3) == "jpg"; }); $file_list = []; foreach ($dir as $fileInfo) { $file_list[$fileInfo->getRealPath()] = $fileInfo; } ksort($file_list); return $file_list; } use Intervention\Image\ImageManagerStatic as Image; Image::configure(array('driver' => 'imagick')); $http = new GuzzleHttp\Client(); $root_dir = "/home/jayr/Pictures/2015"; $micropub_endpoint = "http://lagertha.local/micropub"; foreach (listJpgFiles($root_dir) as $fileInfo) { $in_path = $fileInfo->getRealPath(); $img = Image::make($in_path); $iptc = $img->iptc(); if (false === ($published = DateTimeImmutable::createFromFormat("Y:m:d H:i:s", $img->exif('DateTimeOriginal')))) { $m = sprintf("Skipping %s [couldnt parse date]", $in_path); print $m . PHP_EOL; continue; } $post = [['name' => 'h', 'contents' => 'entry'], ['name' => 'published', 'contents' => $published->format('c')], ['name' => 'photo', 'contents' => fopen($in_path, 'r')]]; if (isset($iptc['Headline'])) { $post[] = ['name' => 'title', 'contents' => $iptc['Headline']];
/** * @inheritdoc */ public static function configure(array $config = array()) { $config['driver'] = Yii::$app->params['images']['driver']; return parent::configure($config); }
/** * Sets the operations params from the url */ private function _set_params() { // Get values from request $params = \Request::route('params'); $filepath = $this->config['abs_path'] . '/' . \Request::route('imagepath'); // echo $params; exit; // If enforcing params, ensure it's a match if ($this->config['enforce_presets'] and !in_array($params, $this->config['presets'])) { throw new HTTP_Exception_404('The requested URL :uri was not found on this server.', array(':uri' => Request::$current->uri())); } $image = new Image(); $image->configure(config('image')); $this->image = $image->make($filepath); // The parameters are separated by hyphens $raw_params = explode('-', $params); // Update param values from passed values foreach ($raw_params as $raw_param) { $name = $raw_param[0]; $value = substr($raw_param, 1, strlen($raw_param) - 1); if ($name == 'c') { $this->url_params[$name] = TRUE; // When croping, we must have a width and height to pass to imagecreatetruecolor method // Make width the height or vice versa if either is not passed if (empty($this->url_params['w'])) { $this->url_params['w'] = $this->url_params['h']; } if (empty($this->url_params['h'])) { $this->url_params['h'] = $this->url_params['w']; } } elseif (key_exists($name, $this->url_params)) { // Remaining expected params (w, h, q) $this->url_params[$name] = $value; } else { // Watermarks or invalid params $this->url_params[$raw_param] = $raw_param; } } // Do not scale up images if (!$this->config['scale_up']) { if ($this->url_params['w'] > $this->image->width()) { $this->url_params['w'] = $this->image->width(); } if ($this->url_params['h'] > $this->image->height()) { $this->url_params['h'] = $this->image->height(); } } // Must have at least a width or height if (empty($this->url_params['w']) and empty($this->url_params['h'])) { throw new HTTP_Exception_404('The requested URL :uri was not found on this server.', array(':uri' => Request::$current->uri())); } // Set the url filepath $this->source_file = $filepath; }
/** * @return void */ public function handle() { try { if ($this->getRequestChecksum()) { $uri_root = rtrim(str_replace('{checksum}', $this->getRequestChecksum(), $this->uri_root), '/'); // with trailling left slash if (strpos($this->getCleanUri(), $uri_root) !== 0) { throw new InvalidArgumentException('Wrong uri root'); } $hashable_uri = substr($this->getCleanUri(), strlen($uri_root)); if ($this->getRequestChecksum() !== $this->token6FromStr($hashable_uri)) { throw new InvalidArgumentException('Invalid checksum value'); } } if (!file_exists($real_file_path = rtrim($this->original_files_root, '/') . '/' . ltrim($this->getRequestFilePath(), '/'))) { throw new InvalidArgumentException('File not exists ' . $real_file_path); } Image::configure(['driver' => 'imagick']); $image = Image::make($real_file_path); foreach ($this->thumb_handlers as $handler_name => $handler_data) { if (preg_match($handler_data[0], $this->getCleanUri(), $matches)) { $handler_data[1]($image, $matches); } } $this->save($image); $response = new Response($image->response(), Response::HTTP_OK, ['content-type' => $image->mime(), 'content-length' => $image->filesize(), 'cache-control' => 'max-age=315360000', 'cache-control' => 'public', 'accept-ranges' => 'bytes']); return $response->prepare($this->request); } catch (Exception $e) { if ($this->is_debug) { return (new SymfonyDisplayer($this->is_debug))->createResponse($e); } return new Response('404 Not found', Response::HTTP_NOT_FOUND); } }
protected function checkImageUpload() { if ($_GET[$this->image_upload_get_key] == $this->image_upload_get_value) { $file = $_FILES['file']; $path = $this->config->getUploadPath(); $name = substr(md5(microtime()), 0, 8) . '_' . $this->sanitizeFilename($file['name']); $full_path = $path . '/' . $name; Image::configure(array('driver' => 'gd')); $image = Image::make($file['tmp_name']); $image->save($full_path); $data = ['path' => $this->config->getUploadURL() . '/' . $name]; echo json_encode($data); exit; } }
<?php require '../../../../../vendor/autoload.php'; use Intervention\Image\ImageManagerStatic as Image; Image::configure(array('driver' => 'gd')); if (!empty($_POST['galleryNonce']) && !empty($_POST['userId']) && !empty($_POST['userEmail']) && $_POST['galleryNonce'] == '12r23tfwegwqt4yefew1^$@36gfu2fg239urt287rbc278vc2bvc7') { $wpUser = $_POST['userId']; $userEmail = $_POST['userEmail']; require_once '../database/identifyGuest.php'; $originals = '../../../../assets/originals/'; $gallery = '../../../../assets/gallery/'; $thumbs = '../../../../assets/thumbs/'; $todaysDate = time(); $allowedSize = 15728640; $allowedFiles = array('jpg', 'JPG', 'jpeg', 'png', 'gif'); if (!empty($_FILES)) { $tempFile = $_FILES['file']['tmp_name']; $fileSize = $_FILES['file']["size"]; $fileType = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); $fileName = pathinfo($_FILES['file']['name'], PATHINFO_FILENAME); if ($fileSize < $allowedSize && in_array($fileType, $allowedFiles)) { $fileNewName = $fileName . '-' . $todaysDate . '.' . $fileType; $img = Image::make($_FILES['file']['tmp_name']); $img->save($originals . $fileNewName); $img->resize(1200, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $img->save($gallery . $fileNewName); $img->fit(350, 350, function ($constraint) { $constraint->aspectRatio();