adaptation pour minio

This commit is contained in:
2022-08-31 11:20:22 +02:00
parent d2fde8a871
commit d539a2a740
23 changed files with 66 additions and 205 deletions

View File

@ -38,7 +38,7 @@ class CropController extends AbstractController
{
// Récupération de l'image à cropper
$file=$request->query->get('file');
$large_image_location = "uploads/$type/$file";
$large_image_location=$this->minio->download($type."/".$file,$type."/".$file,true);
// Récupérer les tailles de l'image
$width = $this->getWidth($large_image_location);
@ -72,13 +72,14 @@ class CropController extends AbstractController
$ratio="1:1";
break;
}
if($max_height>0) {
$scale = $max_height/$height;
if(($width*$scale)>$max_width) {
$scale = $max_width/$width;
}
$this->resizeImage($large_image_location,$width,$height,$scale);
$this->minio->upload($large_image_location,$type."/".$file,false);
}
else $scale=1;
@ -103,12 +104,12 @@ class CropController extends AbstractController
if ($form->get('submit')->isClicked() && $form->isValid()) {
// Récupération des valeurs du formulaire
$data = $form->getData();
$thumb_image_location = "uploads/$type/thumb_".$file;
$tmpdir=$this->appKernel->getProjectDir()."/var/tmp";
$thumb_image_location = "$tmpdir/$type/thumb_".$file;
$cropped = $this->resizeThumbnailImage($thumb_image_location, $large_image_location,$data["ws"],$data["hs"],$data["xs"],$data["ys"],$scale);
// Dépot des fichiers sur minio
$this->minio->upload($large_image_location,$large_image_location,true);
$this->minio->upload($thumb_image_location,$thumb_image_location,true);
$this->minio->upload($thumb_image_location,$type."/thumb_".$file,false);
$submited=true;
}
@ -186,10 +187,13 @@ class CropController extends AbstractController
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
$imageType = image_type_to_mime_type($imageType);
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImageWidth=900;
$newImageHeight=900;
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
switch($imageType) {
case "image/gif":
$source=imagecreatefromgif($image);
@ -197,6 +201,7 @@ class CropController extends AbstractController
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
dump("here");
$source=imagecreatefromjpeg($image);
break;
case "image/png":
@ -204,7 +209,9 @@ class CropController extends AbstractController
$source=imagecreatefrompng($image);
break;
}
imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
$ok=imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
switch($imageType) {
case "image/gif":
imagegif($newImage,$thumb_image_name);
@ -212,14 +219,16 @@ class CropController extends AbstractController
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
imagejpeg($newImage,$thumb_image_name,90);
dump($thumb_image_name);
imagejpeg($newImage,$thumb_image_name,100);
break;
case "image/png":
case "image/x-png":
imagepng($newImage,$thumb_image_name);
break;
}
chmod($thumb_image_name, 0640);
chmod($thumb_image_name, 0640);
return $thumb_image_name;
}

View File

@ -160,7 +160,7 @@ class GroupController extends AbstractController
$userinfo="";
if($data->getOwner()) {
$userinfo.="<img src='".$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$data->getOwner()->getAvatar()])."' class='avatar'>";
$userinfo.="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getOwner()->getAvatar()])."' class='avatar'>";
$userinfo.="<br>".$data->getOwner()->getUsername();
}
@ -513,7 +513,7 @@ class GroupController extends AbstractController
$action.="<a style='cursor:pointer' onClick='addUsers(".$data->getId().")'><i class='fa fa-plus fa-fw'></i></a>";
// Avatar
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$data->getAvatar()])."' class='avatar'>";
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getAvatar()])."' class='avatar'>";
array_push($output["data"],array("DT_RowId"=>"user".$data->getId(),$action,$avatar,$data->getUsername(),$data->getEmail(),"",""));
}
@ -647,7 +647,7 @@ class GroupController extends AbstractController
$action.="<a style='cursor:pointer' onClick='delUsers(".$data->getId().")'><i class='fa fa-minus fa-fw'></i></a>";
// Avatar
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$data->getAvatar()])."' class='avatar'>";
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getAvatar()])."' class='avatar'>";
// Flag manager
$rolegroup="";

View File

@ -27,15 +27,13 @@ class MinioController extends AbstractController
// Répertoire de Destination
$fs = new Filesystem();
$rootdir = $this->getParameter('kernel.project_dir') . '/public';
$fs->mkdir($rootdir."/uploads/ckeditor");
$rootdir = $this->getParameter('kernel.project_dir') . '/var/tmp';
$fs->mkdir($rootdir."/ckeditor");
// Fichier cible
$targetName = uniqid().".".$extention;
$targetFile = "uploads/ckeditor/".$targetName;
$targetUrl = $this->getParameter('appAlias')."uploads/ckeditor/".$targetName;
$targetUrl = $this->generateUrl('app_minio_document',["file"=>"uploads/ckeditor/".$targetName]);
$message = "";
$targetFile = "ckeditor/".$targetName;
$targetUrl = $this->generateUrl('app_minio_document',["file"=>"ckeditor/".$targetName]);
//move_uploaded_file($tmpfile,$targetFile);
$this->minio->upload($tmpfile,$targetFile,true);
@ -49,19 +47,19 @@ class MinioController extends AbstractController
public function logo(Request $request): Response {
return $this->redirectToRoute("app_minio_image",["file"=>"uploads/logo/".$request->getSession()->get("logolight")]);
return $this->redirectToRoute("app_minio_image",["file"=>"logo/".$request->getSession()->get("logolight")]);
}
public function image(Request $request): Response
{
$file=$request->query->get("file");
switch($file) {
case "uploads/avatar/admin.jpg":
case "uploads/avatar/noavatar.png":
case "uploads/avatar/system.jpg":
case "uploads/header/header.jpg":
case "uploads/logo/logo.png":
$file = str_replace("uploads","medias",$file);
case "avatar/admin.jpg":
case "avatar/noavatar.png":
case "avatar/system.jpg":
case "header/header.jpg":
case "logo/logo.png":
$file = "medias/".$file;
$filePath = $file;
$content = file_get_contents($file);
break;
@ -73,15 +71,10 @@ class MinioController extends AbstractController
$content = file_get_contents($file);
}
// C'est du contenu dynamique on download depuis minio
elseif(stripos($file,"uploads")===0) {
else {
$filePath = $this->minio->download($file, $file, true);
$content = file_get_contents($filePath);
}
// C'est du contenu statique on download depuis minio
else {
$filePath = $file;
$content = file_get_contents($file);
}
break;
}

View File

@ -22,7 +22,7 @@ class PublishController extends AbstractController
$ret["from"]["id"]=$this->getUser()->getId();
$ret["from"]["username"]=$this->getUser()->getUsername();
$ret["from"]["displayname"]=$this->getUser()->getDisplayname();
$ret["from"]["avatar"]=$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$this->getUser()->getAvatar()]);
$ret["from"]["avatar"]=$this->generateUrl('app_minio_image',["file"=>"avatar/".$this->getUser()->getAvatar()]);
$update = new Update(

View File

@ -399,7 +399,7 @@ class RestController extends AbstractFOSRestController
$output["userposition"]=$user->getPosition();
$output["userpostaladress"]=$user->getPostaladress();
$output["usertelephonenumber"]=$user->getTelephonenumber();
$output["useravatar"]="https://".str_replace("//","/",$this->getParameter("appWeburl").$this->getParameter("appAlias").$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$user->getAvatar()],true));
$output["useravatar"]="https://".str_replace("//","/",$this->getParameter("appWeburl").$this->getParameter("appAlias").$this->generateUrl('app_minio_image',["file"=>"avatar/".$user->getAvatar()],true));
$output["userniveau01"]=$this->niveau01Format($user->getNiveau01());
$output["userniveau02"]=$this->niveau02Format($user->getNiveau02());
$output["usergroups"]=[];

View File

@ -255,7 +255,7 @@ class UserController extends AbstractController
$tmp=array();
if($access=="admin"||$access=="modo") array_push($tmp,$action);
array_push($tmp,"<img src='".$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$data->getAvatar()])."' class='avatar'>");
array_push($tmp,"<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getAvatar()])."' class='avatar'>");
array_push($tmp,$data->getUsername());
array_push($tmp,$data->getLastname());