if isset file php and laravel

Imagick Example

  if(isset( $_FILES["image"] ) && !empty( $_FILES["image"]["name"] ))
            {
            $drive = "drive/temp/";
            $im = new Imagick( $_FILES["image"]["tmp_name"]);
            
            $finalWidth = $_POST['width'];
            $finalHeight = $_POST['height'];
            $size = $_POST['size'];
            
            $name = time().".jpg";//$_FILES["image"]["name"];
            
            $imageprops = $im->getImageGeometry();
                $width = $imageprops['width'];
                $height = $imageprops['height'];
                if($height > $finalHeight){
                $newHeight = $finalHeight;
                $newWidth = ($finalHeight / $height) * $width;
                }else{
                $newWidth = $imageprops['width'];
                $newHeight = $imageprops['height'];
                }
               //$im->resizeImage($newWidth,$newHeight, Imagick::FILTER_MITCHELL, 0.9, true); 
                $im->scaleImage(0, $finalHeight);
                
                if(isset( $_FILES["imagebg"] ) && !empty( $_FILES["imagebg"]["name"] ) )
                {
                    $canvas = new Imagick($_FILES["imagebg"]["tmp_name"]);
                    $canvas->resizeImage($finalWidth, $finalHeight,  Imagick::FILTER_LANCZOS,1);
                }else
                {
                    $canvas = new Imagick();
                    $canvas->newImage($finalWidth, $finalHeight,  $_POST['bgcolor'], 'jpg');
                }     
                $canvas->blurImage(25, 5);
                $pos = ($finalWidth - $newWidth)/2;
                $canvas->compositeImage($im, Imagick::COMPOSITE_OVER,  $pos, 0);
                $canvas->setOption('jpeg:extent', $size.'kb');
                $canvas->setImageFormat( "jpeg" );
            
            //$im->blurImage(25, 5);
            //$im->adaptiveSharpenImage(10,5);
            //$im->unsharpMaskImage(0, 0.5, 1, 0);
            //$im->setImageResolution( 800, 300 );
            //$im->setResolution(800,300);
            //$im->resampleImage  (800,300,imagick::RESOLUTION_PIXELSPERINCH,1);
            //$im->cropThumbnailImage( 800, 300 );
            //$im->setImageCompressionQuality(70);
            //$im->setImageCompression(true);
            //$im->scaleImage(0, 300);
            //$im->adaptiveResizeImage(800,300);
            //$im->liquidRescaleImage(800, 300, 3, 18);
            //$im->resizeImage(800, 300,  Imagick::FILTER_LANCZOS,1);
            //$im->sharpenImage(0, 3);
            //$im->adaptiveBlurImage(5, 1, 0);
            
            if (file_exists($drive.$name)) {
                try{
                    unlink($drive.$name);
                }
                catch(Exception $ex)
                {
                echo $ex->getMessage()."Adi";
                }  
            }
            $canvas->writeImage($drive.$name);
            //print_r($canvas->identifyImage());
            return redirect("image-resizer")->withSuccess('drive/temp/'.$name);         
            }
            
        return view('imageresizer',['name'=>'drive/temp/'.$name,'title'=>'Online Image Resizer','isUpload'=>1]);

Discover more from Soa Technology | Aditya Website Development Designing Company

Subscribe to get the latest posts sent to your email.



Leave a Reply

Discover more from Soa Technology | Aditya Website Development Designing Company

Subscribe now to keep reading and get access to the full archive.

Continue reading