public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $mimetype = $fileview->getMimeType($path); $path = \OC_Helper::mimetypeIcon($mimetype); $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT)); $svgPath = substr_replace($path, 'svg', -3); if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) { // http://www.php.net/manual/de/imagick.setresolution.php#85284 $svg = new \Imagick(); $svg->readImage($svgPath); $res = $svg->getImageResolution(); $x_ratio = $res['x'] / $svg->getImageWidth(); $y_ratio = $res['y'] / $svg->getImageHeight(); $svg->removeImage(); $svg->setResolution($maxX * $x_ratio, $maxY * $y_ratio); $svg->setBackgroundColor(new \ImagickPixel('transparent')); $svg->readImage($svgPath); $svg->setImageFormat('png32'); $image = new \OC_Image(); $image->loadFromData($svg); } else { $image = new \OC_Image($path); } return $image; }
/** * @param $width * @param $height * @return self */ public function resize($width, $height) { $this->preModify(); // this is the check for vector formats because they need to have a resolution set // this does only work if "resize" is the first step in the image-pipeline if ($this->isVectorGraphic()) { // the resolution has to be set before loading the image, that's why we have to destroy the instance and load it again $res = $this->resource->getImageResolution(); $x_ratio = $res['x'] / $this->getWidth(); $y_ratio = $res['y'] / $this->getHeight(); $this->resource->removeImage(); $newRes = ["x" => $width * $x_ratio, "y" => $height * $y_ratio]; // only use the calculated resolution if we need a higher one that the one we got from the metadata (getImageResolution) // this is because sometimes the quality is much better when using the "native" resulution from the metadata if ($newRes["x"] > $res["x"] && $newRes["y"] > $res["y"]) { $this->resource->setResolution($newRes["x"], $newRes["y"]); } else { $this->resource->setResolution($res["x"], $res["y"]); } $this->resource->readImage($this->imagePath); $this->setColorspaceToRGB(); } $width = (int) $width; $height = (int) $height; $this->resource->resizeimage($width, $height, \Imagick::FILTER_UNDEFINED, 1, false); $this->setWidth($width); $this->setHeight($height); $this->postModify(); return $this; }
public function run() { $faker = Faker::create(); $imgDir = public_path() . DS . 'assets' . DS . 'upload' . DS . 'images'; if (!File::exists($imgDir)) { File::makeDirectory($imgDir, 0755); } File::cleanDirectory($imgDir, true); foreach (range(1, 500) as $index) { $dir = $imgDir . DS . $index; if (!File::exists($dir)) { File::makeDirectory($dir, 0755); } $width = $faker->numberBetween(800, 1024); $height = $faker->numberBetween(800, 1024); $orgImg = $faker->image($dir, $width, $height); chmod($orgImg, 0755); $img = str_replace($dir . DS, '', $orgImg); $image = new Imagick($orgImg); $dpi = $image->getImageResolution(); $dpi = $dpi['x'] > $dpi['y'] ? $dpi['x'] : $dpi['y']; $size = $image->getImageLength(); $extension = strtolower($image->getImageFormat()); //get 5 most used colors from the image $color_extractor = new ColorExtractor(); $myfile = $orgImg; $mime_type = $image->getImageMimeType(); switch ($mime_type) { case 'image/jpeg': $palette_obj = $color_extractor->loadJpeg($myfile); break; case 'image/png': $palette_obj = $color_extractor->loadPng($myfile); break; case 'image/gif': $palette_obj = $color_extractor->loadGif($myfile); break; } $main_color = ''; if (is_object($palette_obj)) { $arr_palette = $palette_obj->extract(5); if (!empty($arr_palette)) { $main_color = strtolower($arr_palette[0]); for ($i = 1; $i < count($arr_palette); $i++) { $main_color .= ',' . strtolower($arr_palette[$i]); } } } //update field main_color from images table $image_obj = VIImage::findorFail((int) $index); $image_obj->main_color = $main_color; $image_obj->save(); $id = VIImageDetail::insertGetId(['path' => 'assets/upload/images/' . $index . '/' . $img, 'height' => $height, 'width' => $width, 'ratio' => $width / $height, 'dpi' => $dpi, 'size' => $size, 'extension' => $extension, 'type' => 'main', 'image_id' => $index]); BackgroundProcess::makeSize($id); } }
/** * Return image resolution based on the Image object provided. * Please note that this method seems to return the image density, or DPI, * not it's output resolution. * * @param Image $image * * @return ImageDimensions */ protected function getImageResolution(Image $image) { if (!$image->isHydrated()) { throw new ImageManagerException(ImageManager::ERR_NOT_HYDRATED); } $img = new \Imagick(); $img->readImageBlob($image->getData()); $d = $img->getImageResolution(); $dimensions = new ImageDimensions($d['x'], $d['y']); return $dimensions; }
/** * @param $width * @param $height * @return Pimcore_Image_Adapter */ public function resize($width, $height) { // this is the check for vector formats because they need to have a resolution set // this does only work if "resize" is the first step in the image-pipeline if ($this->isVectorGraphic()) { // the resolution has to be set before loading the image, that's why we have to destroy the instance and load it again $res = $this->resource->getImageResolution(); $x_ratio = $res['x'] / $this->resource->getImageWidth(); $y_ratio = $res['y'] / $this->resource->getImageHeight(); $this->resource->removeImage(); $this->resource->setResolution($width * $x_ratio, $height * $y_ratio); $this->resource->readImage($this->imagePath); } else { $this->resource->resizeimage($width, $height, Imagick::FILTER_UNDEFINED, 1, false); } $this->setWidth($width); $this->setHeight($height); $this->reinitializeImage(); return $this; }
/** * @param $width * @param $height * @return Pimcore_Image_Adapter */ public function resize($width, $height) { // this is the check for vector formats because they need to have a resolution set // this does only work if "resize" is the first step in the image-pipeline $type = $this->resource->getimageformat(); $vectorTypes = array("EPT", "EPDF", "EPI", "EPS", "EPS2", "EPS3", "EPSF", "EPSI", "EPT", "PDF", "PFA", "PFB", "PFM", "PS", "PS2", "PS3", "PSB", "SVG", "SVGZ"); if (in_array($type, $vectorTypes)) { // the resolution has to be set before loading the image, that's why we have to destroy the instance and load it again $res = $this->resource->getImageResolution(); $x_ratio = $res['x'] / $this->resource->getImageWidth(); $y_ratio = $res['y'] / $this->resource->getImageHeight(); $this->resource->removeImage(); $this->resource->setResolution($width * $x_ratio, $height * $y_ratio); $this->resource->readImage($this->imagePath); } else { $this->resource->resizeimage($width, $height, Imagick::FILTER_UNDEFINED, 1, false); } $this->setWidth($width); $this->setHeight($height); $this->reinitializeImage(); return $this; }
public function updateImage() { if (!Request::ajax()) { return App::abort(404); } $arrReturn = ['status' => 'error']; $id = Input::has('id') ? Input::get('id') : 0; if ($id) { $create = false; try { $image = VIImage::findorFail((int) Input::get('id')); } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) { return App::abort(404); } $message = 'has been updated successful'; } else { $create = true; $image = new VIImage(); $message = 'has been created successful'; } if ($create && !Input::hasFile('image')) { return ['status' => 'error', 'message' => 'You need to upload at least 1 image.']; } $image->name = Input::get('name'); $image->short_name = Str::slug($image->name); $image->description = Input::get('description'); $image->keywords = Input::get('keywords'); $image->keywords = rtrim(trim($image->keywords), ','); $image->model = Input::get('model'); $image->model = rtrim(trim($image->model), ','); $image->artist = Input::get('artist'); $image->age_from = Input::get('age_from'); $image->age_to = Input::get('age_to'); $image->gender = Input::get('gender'); $image->number_people = Input::get('number_people'); $pass = $image->valid(); if ($pass->passes()) { if (Input::hasFile('image')) { $color_extractor = new ColorExtractor(); $myfile = Input::file('image'); $mime_type = $myfile->getClientMimeType(); switch ($mime_type) { case 'image/jpeg': $palette_obj = $color_extractor->loadJpeg($myfile); break; case 'image/png': $palette_obj = $color_extractor->loadPng($myfile); break; case 'image/gif': $palette_obj = $color_extractor->loadGif($myfile); break; } $main_color = ''; if (is_object($palette_obj)) { $arr_palette = $palette_obj->extract(5); if (!empty($arr_palette)) { $main_color = strtolower($arr_palette[0]); for ($i = 1; $i < count($arr_palette); $i++) { $main_color .= ',' . strtolower($arr_palette[$i]); } } } $image->main_color = $main_color; } $image->save(); //insert into statistic_images table if ($create) { StatisticImage::create(['image_id' => $image->id, 'view' => '0', 'download' => '0']); } foreach (['category_id' => 'categories', 'collection_id' => 'collections'] as $key => $value) { $arrOld = $remove = $add = []; $old = $image->{$value}; $data = Input::has($key) ? Input::get($key) : []; $data = (array) json_decode($data[0]); if (!empty($old)) { foreach ($old as $val) { if (!in_array($val->id, $data)) { $remove[] = $val->id; } else { $arrOld[] = $val->id; } } } foreach ($data as $id) { if (!$id) { continue; } if (!in_array($id, $arrOld)) { $add[] = $id; } } if (!empty($remove)) { $image->{$value}()->detach($remove); } if (!empty($add)) { $image->{$value}()->attach($add); } foreach ($add as $v) { $arrOld[] = $v; } $image->{'arr' . ucfirst($value)} = $arrOld; } $path = public_path('assets' . DS . 'upload' . DS . 'images' . DS . $image->id); if ($create) { $main = new VIImageDetail(); $main->image_id = $image->id; $main->type = 'main'; File::makeDirectory($path, 0755, true); } else { $main = VIImageDetail::where('type', 'main')->where('image_id', $image->id)->first(); File::delete(public_path($main->path)); } if (Input::hasFile('image')) { $file = Input::file('image'); $name = $image->short_name . '.' . $file->getClientOriginalExtension(); $file->move($path, $name); $imageChange = true; } else { if (Input::has('choose_image') && Input::has('choose_name')) { $chooseImage = Input::get('choose_image'); $name = Input::get('choose_name'); file_put_contents($path . DS . $name, file_get_contents($chooseImage)); $imageChange = true; } } if (isset($imageChange)) { $main->path = 'assets/upload/images/' . $image->id . '/' . $name; $img = Image::make($path . DS . $name); $main->width = $img->width(); $main->height = $img->height(); $main->ratio = $main->width / $main->height; $img = new Imagick($path . DS . $name); $dpi = $img->getImageResolution(); $main->dpi = $dpi['x'] > $dpi['y'] ? $dpi['x'] : $dpi['y']; $main->size = $img->getImageLength(); $main->extension = strtolower($img->getImageFormat()); $main->save(); BackgroundProcess::makeSize($main->detail_id); $image->changeImg = true; if ($create) { $image->dimension = $main->width . 'x' . $main->height; $image->newImg = true; $image->path = URL . '/pic/large-thumb/' . $image->short_name . '-' . $image->id . '.jpg'; } } $arrReturn['status'] = 'ok'; $arrReturn['message'] = "{$image->name} {$message}."; $arrReturn['data'] = $image; return $arrReturn; } $arrReturn['message'] = ''; $arrErr = $pass->messages()->all(); foreach ($arrErr as $value) { $arrReturn['message'] .= "{$value}\n"; } return $arrReturn; }
public function uploadFile() { if (Auth::user()->check()) { if (Input::hasFile('myfiles')) { $name = Input::get('name'); $short_name = Str::slug($name); $description = Input::get('description'); $keywords = Input::get('keywords'); $keywords = rtrim(trim($keywords), ','); $model = Input::get('model'); $model = rtrim(trim($model), ','); $artist = Input::get('artist'); $age_from = Input::get('age_from'); $age_to = Input::get('age_to'); $gender = Input::get('gender'); $number_people = Input::get('number_people'); $type_id = Input::get('type_id'); $arr_category_ids = Input::get('category_id'); $faker = Faker::create(); $destination_store = Input::get('destination_store'); //insert to images table // $keywords = ''; // for( $i = 0; $i < $faker->numberBetween(4, 9); $i++ ) { // $keywords .= $faker->word.','; // } // $keywords = rtrim($keywords, ','); // $name = $faker->name; // $short_name = Str::slug($name); // $gender = $faker->randomElement($array = array ('male','female','both','any')); // $age_from = $faker->numberBetween(0, 90); // $age_to = $faker->numberBetween(0, 90); // while($age_from >$age_to){ // $age_from = $faker->numberBetween(0, 90); // $age_to = $faker->numberBetween(0, 90); // } $ethnicity = $faker->randomElement($array = array('african', 'african_american', 'black', 'brazilian', 'chinese', 'caucasian', 'east_asian', 'hispanic', 'japanese', 'middle_eastern', 'native_american', 'pacific_islander', 'south_asian', 'southeast_asian', 'other', 'any')); //$number_people = $faker->numberBetween(0, 10); $editorial = $faker->numberBetween(0, 1); //$type_id = $faker->numberBetween(1, 3); $color_extractor = new ColorExtractor(); $myfiles = Input::file('myfiles'); $mime_type = $myfiles[0]->getClientMimeType(); switch ($mime_type) { case 'image/jpeg': $palette_obj = $color_extractor->loadJpeg($myfiles[0]); break; case 'image/png': $palette_obj = $color_extractor->loadPng($myfiles[0]); break; case 'image/gif': $palette_obj = $color_extractor->loadGif($myfiles[0]); break; default: # code... break; } $main_color = ''; if (is_object($palette_obj)) { $arr_palette = $palette_obj->extract(5); if (!empty($arr_palette)) { $main_color = strtolower($arr_palette[0]); for ($i = 1; $i < count($arr_palette); $i++) { $main_color .= ',' . strtolower($arr_palette[$i]); } } } $image_id = VIImage::insertGetId(['name' => $name, 'short_name' => $short_name, 'description' => $description, 'keywords' => $keywords, 'main_color' => $main_color, 'type_id' => $type_id, 'model' => $model, 'artist' => $artist, 'gender' => $gender, 'age_from' => $age_from, 'age_to' => $age_to, 'ethnicity' => $ethnicity, 'number_people' => $number_people, 'editorial' => $editorial, 'author_id' => Auth::user()->get()->id, 'store' => $destination_store]); //insert into statistic_images table StatisticImage::create(['image_id' => $image_id, 'view' => '0', 'download' => '0']); //insert into images_categories table if (!empty($arr_category_ids)) { foreach ($arr_category_ids as $category_id) { ImageCategory::create(['image_id' => $image_id, 'category_id' => $category_id]); } } $result = array(); for ($i = 0; $i < count($myfiles); $i++) { $file = $myfiles[$i]; $extension = strtolower($file->getClientOriginalExtension()); $file_name = $faker->lexify($string = '???????????????????'); $url = $file_name . "." . $extension; //get image's information $file_content = file_get_contents($file); $image = new Imagick(); $image->pingImageBlob($file_content); $dpi = $image->getImageResolution(); $dpi = $dpi['x'] > $dpi['y'] ? $dpi['x'] : $dpi['y']; $size = $image->getImageLength(); $width = $image->getImageWidth(); $height = $image->getImageHeight(); $result[$i]['filename'] = $file->getClientOriginalName(); $result[$i]['result'] = true; if ($destination_store == 'dropbox') { try { $this->filesystem->write($url, $file_content); } catch (\Dropbox\Exception $e) { $result[$i]['result'] = false; echo $e->getMessage(); } } else { $upload_folder = 'assets' . DS . 'upload' . DS . 'images' . DS . $image_id; $imgDir = public_path() . DS . $upload_folder; if (!File::exists($imgDir)) { File::makeDirectory($imgDir, 0755); } $url = $upload_folder . DS . $url; $url = str_replace('\\', '/', $url); if (!VIImage::upload($file, $imgDir, $width, true, $file_name)) { $result[$i]['result'] = false; } } //insert to image_details table $id = VIImageDetail::insertGetId(['path' => $url, 'height' => $height, 'width' => $width, 'ratio' => $width / $height, 'dpi' => $dpi, 'size' => $size, 'extension' => $extension, 'type' => 'main', 'size_type' => $i + 1, 'image_id' => $image_id]); if (!$id) { $result[$i]['result'] = false; } } Session::flash('message', $result); } else { Session::flash('message', 'Please choose the image!'); } return Redirect::route('upload-page'); } return Redirect::route('account-sign-in'); }
function imgetimagesize($imagefile) { global $enable_imagick; if ($enable_imagick && class_exists('Imagick')) { $im = new Imagick(); // $im->setResolution( 300, 300 ); $im->readImage($imagefile); $width = $im->getImageWidth(); $height = $im->getImageHeight(); $type = $im->getImageType(); $imageResolution = $im->getImageResolution(); $resolutionX = round($imageResolution['x'] * 2.54, 2); $resolutionY = round($imageResolution['y'] * 2.54, 2); $mime = $im->getImageMimeType(); $params = $im->getImageProperties("*"); $attr = "width=\"{$width}\" height=\"{$height}\""; } else { list($width, $height, $type, $attr) = getimagesize($imagefile, $imageinfo); } return array("width" => $width, "height" => $height, "type" => $type, "attr" => $attr, "resolution_x" => $resolutionX, "resolution_y" => $resolutionY, "mime_type" => $mime, "properties" => $params); }
if (!move_uploaded_file($file['tmp_name'], $fullpathfilename)) { $return['error'] = 'Upload error.'; $return['status'] = -1; unlink($file['tmp_name']); break; } try { $imagick = new Imagick($fullpathfilename); $width = $imagick->getImageWidth(); $height = $imagick->getImageHeight(); if ($width > $height) { $sqwidth = $height; } else { $sqwidth = $width; } $resolution = $imagick->getImageResolution(); $ppi = $resolution['x']; if ($sqwidth < ITEMPHOTOMINWIDTH) { throw new Exception('Photo is too small. Shortest side must be at least ' . ITEMPHOTMINWIDTH . 'px.'); } if ($ppi < ITEMPHOTOMINPPI) { throw new Exception('Photo is too small. Must be at least ' . ITEMPHOTOMINPPI . 'ppi.'); } $sq50 = 'sq50-' . $filename; $sq150 = 'sq150-' . $filename; $sq300 = 'sq300-' . $filename; $sq500 = 'sq500-' . $filename; Utility::magickResizeImage($fullpathfilename, PHOTODIR . $sq50, 50); Utility::magickResizeImage($fullpathfilename, PHOTODIR . $sq150, 150); Utility::magickResizeImage($fullpathfilename, PHOTODIR . $sq300, 300); Utility::magickResizeImage($fullpathfilename, PHOTODIR . $sq500, 500);
$ret['imagetype'] = $fileExtension; $ImageSize = $_FILES['avatarfile']['size']; // Obtain original image size $ret['size'] = $ImageSize; //if ($ImageSize>10000000){die(json_encode(array("jquery-upload-file-error"=>'You require an image with a size of NOT more that 10MB. Your Image is Larger');} $imagename = basename($_FILES["avatarfile"]["name"]); $clean = '../images/avatars/' . $imagename; //UPLOAD IMAGE HERE - TO DELETE LATER if (!move_uploaded_file($_FILES["avatarfile"]["tmp_name"], $clean)) { die(json_encode(array("jquery-upload-file-error" => 'Error Uploading the image. Please try again later'))); } else { $editimage = $clean; //GET ORIGINAL FROM SETTINGS $original = new Imagick($editimage); //CHECK RESOLUTION AND SIZE $myarr = $original->getImageResolution(); // Array ( [x] => 72 [y] => 72 ) $mres = $myarr['x']; $ret['resolution'] = $mres; //if($mres<200){ die(json_encode(array("jquery-upload-file-error"=>'You require an image with a DPI of over 200px. Your Image has '. $mres))); } $oriental = 3; list($width, $height) = getimagesize($editimage); $ret['dimensions'] = $width . 'X' . $height; if ($width > $height) { $oriental = 1; $ret['orientation'] = 'Landscape'; } else { $oriental = 2; } $ret['orientation'] = "Portrait"; $filename = $out_large;
/** * @return array */ public function getResolution() { $resolution = $this->im->getImageResolution(); return [$resolution['x'], $resolution['y']]; }
/** * Создаёт уменьшенную копию изображений разных форматов с помощью ImageMagick. * Уменьшенная копия будет в формате png. * @param source string <p>Исходное изображение.</p> * @param dest string <p>Файл, куда должна быть помещена уменьшенная копия.</p> * @param x mixed <p>Ширина исходного изображения.</p> * @param y mixed <p>Высота исходного изображения.</p> * @param resize_x mixed<p>Ширина уменьшенной копии изображения.</p> * @param resize_y mixed<p>Высота уменьшенной копии изображения.</p> * @return array * Возвращает размеры созданной уменьшенной копии изображения. */ function im_create_png_thumbnail($source, $dest, $x, $y, $resize_x, $resize_y) { $thumbnail = new Imagick($source); $resolution = $thumbnail->getImageResolution(); $resolution_ratio_x = $resolution['x'] / $x; $resolution_ratio_y = $resolution['y'] / $y; // get background color of source image $color = $thumbnail->getImageBackgroundColor(); if ($x >= $y) { // calculate proportions of destination image $ratio = $y / $x; $resize_y = $resize_y * $ratio; } else { $ratio = $x / $y; $resize_x = $resize_x * $ratio; } $thumbnail->removeImage(); $thumbnail->setResolution($resize_x * $resolution_ratio_x, $resize_y * $resolution_ratio_y); $thumbnail->readImage($source); if (!$thumbnail->setImageFormat('png')) { throw new ConvertPNGException(); } // fill destination image with source image background color // (for transparency in svg for example) $thumbnail->paintTransparentImage($color, 0.0, 0); $dimensions = array(); $dimensions['x'] = $thumbnail->getImageWidth(); $dimensions['y'] = $thumbnail->getImageHeight(); $thumbnail->writeImage($dest); $thumbnail->clear(); $thumbnail->destroy(); return $dimensions; }
include "common/constants.inc"; $images = array('couple_dubstep.jpg'); foreach ($images as $image) { echo '==========' . HTMLEOL; echo $image . HTMLEOL; $resource = new Imagick('photos/' . $image); $width = $resource->getImageWidth(); echo 'width=' . $width; $height = $resource->getImageHeight(); echo 'height=' . $height; $properties = $resource->getImageProperties(); foreach ($properties as $key => $value) { echo $key . '=>' . $value . HTMLEOL; } $resolution = $resource->getImageResolution(); foreach ($resolution as $key => $value) { echo 'Resolution: ' . $key . '=>' . $value . HTMLEOL; } $size = $resource->getSize(); foreach ($size as $key => $value) { echo 'Resolution: ' . $key . '=>' . $value . HTMLEOL; } echo 'imageformat=' . $resource->getImageFormat() . HTMLEOL; echo 'imagesize=' . round($resource->getImageSize() / 1024) . HTMLEOL; echo '<div>'; echo ' <figure>'; echo ' <img src="photos/' . $image . '">'; echo ' </figure>'; echo ' <figcaption>' . $image . '</figcaption>'; echo '</div>';
private function sizes() { $imageDetailId = $this->option('image_detail_id'); $image = VIImageDetail::select('images.short_name', 'images.id', 'image_details.path', 'image_details.detail_id', 'image_details.ratio')->join('images', 'images.id', '=', 'image_details.image_id')->where('image_details.detail_id', $imageDetailId)->first(); if (!is_object($image)) { $this->error('Image ' . $imageDetailId . ' cannot be found.'); return; } $this->deleteExistSizes($imageDetailId, $image->id); $img = Image::make(public_path($image->path)); $width = $img->width(); $height = $img->height(); $w = $h = null; $arrSizes = $arrInsert = $extra = []; if ($width * $height > 24000000) { $sizeType = 4; $arrSizes = [['w' => $width / 2, 'h' => $height / 2, 'sizeType' => 3], ['w' => $image->ratio > 1 ? 1000 : null, 'h' => $image->ratio <= 1 ? 1000 : null, 'sizeType' => 2], ['w' => $image->ratio > 1 ? 500 : null, 'h' => $image->ratio <= 1 ? 500 : null, 'sizeType' => 1]]; } else { if ($width > 1500 || $height > 1500) { $sizeType = 3; $arrSizes = [['w' => $image->ratio > 1 ? 1000 : null, 'h' => $image->ratio <= 1 ? 1000 : null, 'sizeType' => 2], ['w' => $image->ratio > 1 ? 500 : null, 'h' => $image->ratio <= 1 ? 500 : null, 'sizeType' => 1]]; } else { if ($width >= 1000 || $height >= 1000) { if ($width > 1000 || $height > 1000) { $h = $w = $image->ratio > 1 ? 1000 : null; if ($w == null) { $h = 1000; } $extra = ['w' => $w, 'h' => $h]; } $sizeType = 2; $arrSizes = [['w' => $image->ratio > 1 ? 500 : null, 'h' => $image->ratio <= 1 ? 500 : null, 'sizeType' => 1]]; } else { if ($width > 500 || $height > 500) { $h = $w = $image->ratio > 1 ? 500 : null; if ($w == null) { $h = 500; } $extra = ['w' => $w, 'h' => $h]; } $sizeType = 1; } } } $arrUpdate = ['size_type' => $sizeType]; if (!empty($extra)) { $img = Image::make(public_path($image->path)); $img->resize($extra['w'], $extra['h'], function ($constraint) { $constraint->aspectRatio(); }); $img->save(public_path($image->path)); $arrUpdate['width'] = $img->width(); $arrUpdate['height'] = $img->height(); $arrUpdate['size'] = $img->filesize(); } $arrInsert = []; foreach ($arrSizes as $size) { $img = Image::make(public_path($image->path)); $img->resize($size['w'], $size['h'], function ($constraint) { $constraint->aspectRatio(); }); $path = 'assets/upload/images/' . $image->id . '/' . $size['sizeType'] . '-' . $image->short_name . '.jpg'; $img->save(public_path($path)); $size_type = $size['sizeType']; $width = $img->width(); $height = $img->height(); $ratio = $width / $height; $img = new Imagick(public_path($path)); $dpi = $img->getImageResolution(); $dpi = $dpi['x'] > $dpi['y'] ? $dpi['x'] : $dpi['y']; $size = $img->getImageLength(); $arrInsert[] = ['width' => $width, 'height' => $height, 'ratio' => $ratio, 'dpi' => $dpi, 'size' => $size, 'size_type' => $size_type, 'path' => $path, 'image_id' => $image->id, 'type' => '', 'extension' => 'jpeg']; } if (!empty($arrInsert)) { VIImageDetail::insert($arrInsert); } VIImageDetail::where('detail_id', $imageDetailId)->update($arrUpdate); $this->info(count($arrInsert) . ' image(s) has been inserted.'); }