- Fix résolution dpi

- Create thumbnailImage by DB
This commit is contained in:
Vincent BRIDIER 2020-02-03 12:28:22 +01:00
parent 3359141d74
commit c120a3de2f
3 changed files with 17 additions and 12 deletions

View file

@ -161,7 +161,7 @@ class UploadController extends Controller {
}
$resolutions = $im->getImageResolution();
$media->resolution = round($resolutions['x'] * 2.54, 2);
$media->resolution = round($resolutions['x'] * 2.54);
$imageprops = $im->getImageGeometry();
$media->largeur = $imageprops['width'];
$media->hauteur = $imageprops['height'];

View file

@ -1,5 +1,6 @@
<?php
namespace App\Http\Traits;
use App\Models\Format;
use Illuminate\Support\Facades\Storage;
trait MediaTools {
@ -58,32 +59,36 @@ trait MediaTools {
}*/
// create preview
$format = Format::withoutGlobalScope('App\Scopes\SystemScope')->where('libelle', '=', 'preview')->first();
$fp = public_path()."/".$media->folder.$media->uid.'_preview.'.$extension;
if($media->extension == "gif" ){
if($media->largeur >= 1500 || $media->hauteur >= 1500 || $media->largeur == ""){
if($media->largeur >= $format->largeur || $media->hauteur >= $format->hauteur || $media->largeur == ""){
$im = $im->coalesceImages();
foreach ($im as $frame) {
$frame->thumbnailImage(1500, 1500);
$frame->setImagePage(1500, 1500, 0, 0);
$frame->thumbnailImage($format->largeur, $format->hauteur);
$frame->setImagePage($format->largeur, $format->hauteur, 0, 0);
}
$im = $im->deconstructImages();
}
$im->writeImages($fp, true);
}else{
if($media->largeur >= 1500 || $media->hauteur >= 1500 || $media->largeur == ""){
$im->thumbnailImage(1500, 1500 , true);
if($media->largeur >= $format->largeur || $media->hauteur >= $format->hauteur || $media->largeur == ""){
$im->thumbnailImage($format->largeur, $format->hauteur , true);
}
$im->writeImage($fp);
}
// create thumb
$im->setImageBackgroundColor('#ffffff');
$im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_REMOVE);
$im->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
$im->stripImage();
$format = Format::withoutGlobalScope('App\Scopes\SystemScope')->where('libelle', '=', 'thumb')->first();
if ($extension != "png"){
$im->setImageBackgroundColor('#ffffff');
$im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_REMOVE);
$im->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
$im->stripImage();
}
$fp = public_path()."/".$media->folder.$media->uid.'_thumb.'.$extension;
$im->thumbnailImage(200, 200 , true);
$im->thumbnailImage($format->largeur, $format->hauteur , true);
$im->writeImage($fp);
$im->destroy();
unset($im);

View file

@ -212,7 +212,7 @@
<input type="text" id="hauteur" name="hauteur" readonly >
</div>
<div class="row">
<label for="resolution">Résolution</label>
<label for="resolution">Résolution (dpi)</label>
<input type="text" id="resolution" name="resolution" readonly >
</div>
<div class="row">