fix(continuous-integration): correction php-cs-fixer
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good
This commit is contained in:
@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Service\MinioService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
class CropController extends AbstractController
|
||||
{
|
||||
@ -23,81 +23,82 @@ class CropController extends AbstractController
|
||||
}
|
||||
|
||||
// Etape 01 - Téléchargement de l'image
|
||||
public function crop01($type,$reportinput): Response
|
||||
public function crop01($type, $reportinput): Response
|
||||
{
|
||||
return $this->render('Crop/crop01.html.twig',[
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'type' => $type,
|
||||
'reportinput' => $reportinput
|
||||
return $this->render('Crop/crop01.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'type' => $type,
|
||||
'reportinput' => $reportinput,
|
||||
]);
|
||||
}
|
||||
|
||||
// Etape 02 - Couper votre l'image
|
||||
public function crop02($type,$reportinput,Request $request)
|
||||
public function crop02($type, $reportinput, Request $request)
|
||||
{
|
||||
// Récupération de l'image à cropper
|
||||
$file=$request->query->get('file');
|
||||
$large_image_location=$this->minio->download($type."/".$file,$type."/".$file,true);
|
||||
$file = $request->query->get('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);
|
||||
$height = $this->getHeight($large_image_location);
|
||||
$max_height=null;
|
||||
$max_width=null;
|
||||
$ratio=null;
|
||||
$width = $this->getWidth($large_image_location);
|
||||
$height = $this->getHeight($large_image_location);
|
||||
$max_height = null;
|
||||
$max_width = null;
|
||||
$ratio = null;
|
||||
|
||||
// Définir le pourcentage de réduction de l'image
|
||||
switch ($type) {
|
||||
case "illustration":
|
||||
$max_height=0;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
|
||||
case "avatar":
|
||||
$max_height=900;
|
||||
$max_width=900;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
case "header":
|
||||
$max_height=1600;
|
||||
$max_width=1600;
|
||||
$ratio="16:2";
|
||||
switch ($type) {
|
||||
case 'illustration':
|
||||
$max_height = 0;
|
||||
$ratio = '1:1';
|
||||
break;
|
||||
|
||||
case 'avatar':
|
||||
$max_height = 900;
|
||||
$max_width = 900;
|
||||
$ratio = '1:1';
|
||||
break;
|
||||
case 'header':
|
||||
$max_height = 1600;
|
||||
$max_width = 1600;
|
||||
$ratio = '16:2';
|
||||
break;
|
||||
case 'hero':
|
||||
$max_height = 1600;
|
||||
$max_width = 1600;
|
||||
$ratio = '16:9';
|
||||
break;
|
||||
case 'image':
|
||||
$max_height = 1600;
|
||||
$max_width = 1600;
|
||||
$ratio = '1:1';
|
||||
break;
|
||||
case "hero":
|
||||
$max_height=1600;
|
||||
$max_width=1600;
|
||||
$ratio="16:9";
|
||||
break;
|
||||
case "image":
|
||||
$max_height=1600;
|
||||
$max_width=1600;
|
||||
$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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Construction du formulaire
|
||||
$submited=false;
|
||||
$submited = false;
|
||||
$form = $this->createFormBuilder()
|
||||
->add('submit',SubmitType::class,array("label" => "Valider","attr" => array("class" => "btn btn-success")))
|
||||
->add('x',HiddenType::class)
|
||||
->add('y',HiddenType::class)
|
||||
->add('w',HiddenType::class)
|
||||
->add('h',HiddenType::class)
|
||||
->add('xs',HiddenType::class)
|
||||
->add('ys',HiddenType::class)
|
||||
->add('ws',HiddenType::class)
|
||||
->add('hs',HiddenType::class)
|
||||
->add('submit', SubmitType::class, ['label' => 'Valider', 'attr' => ['class' => 'btn btn-success']])
|
||||
->add('x', HiddenType::class)
|
||||
->add('y', HiddenType::class)
|
||||
->add('w', HiddenType::class)
|
||||
->add('h', HiddenType::class)
|
||||
->add('xs', HiddenType::class)
|
||||
->add('ys', HiddenType::class)
|
||||
->add('ws', HiddenType::class)
|
||||
->add('hs', HiddenType::class)
|
||||
->getForm();
|
||||
|
||||
// Récupération des data du formulaire
|
||||
@ -107,134 +108,141 @@ class CropController extends AbstractController
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
// Récupération des valeurs du formulaire
|
||||
$data = $form->getData();
|
||||
$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);
|
||||
$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($thumb_image_location,$type."/thumb_".$file,false);
|
||||
$this->minio->upload($thumb_image_location, $type.'/thumb_'.$file, false);
|
||||
|
||||
$submited=true;
|
||||
$submited = true;
|
||||
}
|
||||
|
||||
return $this->render('Crop/crop02.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'form' => $form->createView(),
|
||||
'type' => $type,
|
||||
'file' => $file,
|
||||
'ratio' => $ratio,
|
||||
"reportinput" => $reportinput,
|
||||
"submited" => $submited
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'form' => $form->createView(),
|
||||
'type' => $type,
|
||||
'file' => $file,
|
||||
'ratio' => $ratio,
|
||||
'reportinput' => $reportinput,
|
||||
'submited' => $submited,
|
||||
]);
|
||||
}
|
||||
|
||||
// Calcul de la hauteur
|
||||
protected function getHeight($image) {
|
||||
$size = getimagesize($image);
|
||||
$height = $size[1];
|
||||
return $height;
|
||||
}
|
||||
// Calcul de la hauteur
|
||||
protected function getHeight($image)
|
||||
{
|
||||
$size = getimagesize($image);
|
||||
$height = $size[1];
|
||||
|
||||
// Cacul de la largeur
|
||||
protected function getWidth($image) {
|
||||
$size = getimagesize($image);
|
||||
$width = $size[0];
|
||||
return $width;
|
||||
}
|
||||
return $height;
|
||||
}
|
||||
|
||||
protected function resizeImage($image,$width,$height,$scale) {
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
|
||||
$source=null;
|
||||
// Cacul de la largeur
|
||||
protected function getWidth($image)
|
||||
{
|
||||
$size = getimagesize($image);
|
||||
$width = $size[0];
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
|
||||
return $width;
|
||||
}
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
imagejpeg($newImage,$image,90);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$image);
|
||||
break;
|
||||
}
|
||||
protected function resizeImage($image, $width, $height, $scale)
|
||||
{
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
|
||||
$source = null;
|
||||
|
||||
chmod($image, 0640);
|
||||
return $image;
|
||||
}
|
||||
switch ($imageType) {
|
||||
case 'image/gif':
|
||||
$source = imagecreatefromgif($image);
|
||||
break;
|
||||
case 'image/pjpeg':
|
||||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
$source = imagecreatefromjpeg($image);
|
||||
break;
|
||||
case 'image/png':
|
||||
case 'image/x-png':
|
||||
$source = imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
imagecopyresampled($newImage, $source, 0, 0, 0, 0, $newImageWidth, $newImageHeight, $width, $height);
|
||||
|
||||
protected function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
|
||||
switch ($imageType) {
|
||||
case 'image/gif':
|
||||
imagegif($newImage, $image);
|
||||
break;
|
||||
case 'image/pjpeg':
|
||||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
imagejpeg($newImage, $image, 90);
|
||||
break;
|
||||
case 'image/png':
|
||||
case 'image/x-png':
|
||||
imagepng($newImage, $image);
|
||||
break;
|
||||
}
|
||||
|
||||
chmod($image, 0640);
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale)
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
$fs->remove($thumb_image_name);
|
||||
|
||||
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);
|
||||
$source=null;
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
dump("here");
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
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);
|
||||
$source = null;
|
||||
|
||||
$ok=imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
|
||||
switch ($imageType) {
|
||||
case 'image/gif':
|
||||
$source = imagecreatefromgif($image);
|
||||
break;
|
||||
case 'image/pjpeg':
|
||||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
dump('here');
|
||||
$source = imagecreatefromjpeg($image);
|
||||
break;
|
||||
case 'image/png':
|
||||
case 'image/x-png':
|
||||
$source = imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$thumb_image_name);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$ok = imagecopyresampled($newImage, $source, 0, 0, $start_width, $start_height, $newImageWidth, $newImageHeight, $width, $height);
|
||||
|
||||
switch ($imageType) {
|
||||
case 'image/gif':
|
||||
imagegif($newImage, $thumb_image_name);
|
||||
break;
|
||||
case 'image/pjpeg':
|
||||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
dump($thumb_image_name);
|
||||
imagejpeg($newImage,$thumb_image_name,100);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$thumb_image_name);
|
||||
break;
|
||||
}
|
||||
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);
|
||||
return $thumb_image_name;
|
||||
}
|
||||
|
||||
return $thumb_image_name;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user