image upload

 avatar
Esbjerg82
plain_text
a year ago
1.5 kB
42
Indexable
Never
        $exif = @exif_read_data($fileTmpName);
        $image = imagecreatefromstring(file_get_contents($fileTmpName));
        $imageResize = imagescale($image, $width, $height);

        if ($exif && isset($exif['Orientation'])) {
            switch ($exif['Orientation']) {
                case 3:
                    $imageResize = imagerotate($imageResize, 180, 0);
                    break;
                case 6:
                    $imageResize = imagerotate($imageResize, -90, 0);
                    break;
                case 8:
                    $imageResize = imagerotate($imageResize, 90, 0);
                    break;
            }
        }

        switch ($fileType) {
            case $fileType == "png":
                imagealphablending($imageResize, false);
                imagesavealpha($imageResize, true);
                imagepng($imageResize, $path);
                break;
            case $fileType == "jpg" || $fileType == "jpeg":
                imagejpeg($imageResize, $path);
                break;
            case $fileType == "gif":
                imagegif($imageResize, $path);
                break;
        }

        imagecopy($imageResize, $watermarkImg, imagesx($imageResize) - $sx - $margin_right, imagesy($imageResize) - $sy - $margin_bottom, 0, 0, imagesx($watermarkImg), imagesy($watermarkImg));
        imagepng($imageResize, $path);

        imagedestroy($image);
        imagedestroy($imageResize);