Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

to resize image in orignal size or not to be copress after resize

I want to resize an image in orignal size. For this I am using resize function for jpeg, png, gif using swith case. Code is working properly with png format but it is not working with jpeg

Here is my php code

<?php 

    if(isset($_POST["submit"])) { 
        if(is_array($_FILES)) { 
            $uploadedFile = $_FILES['image']['tmp_name']; 
            $sourceProperties = getimagesize($uploadedFile); 
            $newFileName = time(); 
            $dirPath = "uploads/"; 
            $Path = "resize/"; 
            $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION); 
            $imageType = $sourceProperties[2];

            switch ($imageType) { 
                case IMAGETYPE_PNG: 
                    $imageSrc = imagecreatefrompng($uploadedFile); 
                    $tmp = imageResize($imageSrc,$sourceProperties[0],$sourceProperties[1]); 
                    imagepng($tmp,$Path. $newFileName. "_thump.". $ext,$quality); 
                    break; 
                case IMAGETYPE_JPEG: $imageSrc = imagecreatefromjpeg($uploadedFile); 
                    $tmp = imageResize($imageSrc,$sourceProperties[0],$sourceProperties[1]); 
                    imagejpeg($tmp,$Path. $newFileName. "_thump.". $ext,$quality); 
                    break; 
                case IMAGETYPE_GIF: 
                    $imageSrc = imagecreatefromgif($uploadedFile); 
                    $tmp = imageResize($imageSrc,$sourceProperties[0],$sourceProperties[1]); 
                    imagegif($tmp,$Path. $newFileName. "_thump.". $ext,$quality); 
                    break;
                default: 
                    echo "Invalid Image type."; 
                    exit; 
                    break; 
            }

            move_uploaded_file($uploadedFile, $dirPath. $newFileName. ".". $ext); 
            echo "<script>alert('img resize Successfully'); </script>"; 
        } 
    }

Comments