Created
November 30, 2020 12:42
-
-
Save ErMandeep/41c90f173b748ffbcca13f94475cab55 to your computer and use it in GitHub Desktop.
stop image rotation => upload image using url in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$exif = exif_read_data($url); | |
if (!empty($exif['Orientation'])) { | |
$imageResource = imagecreatefromjpeg($url); // provided that the image is jpeg. Use relevant function otherwise | |
switch ($exif['Orientation']) { | |
case 3: | |
$image = imagerotate($imageResource, 180, 0); | |
break; | |
case 6: | |
$image = imagerotate($imageResource, -90, 0); | |
break; | |
case 8: | |
$image = imagerotate($imageResource, 90, 0); | |
break; | |
default: | |
$image = $imageResource; | |
} | |
} | |
$new_upload_image = imagejpeg($image, $img, 90); | |
if (!empty($new_upload_image)): | |
if (file_exists(DIR_FS_SITE_UPLOAD . 'photo/' . $type . '/thumb/' . $image_name)): | |
$admin_user->set_pass_msg('Image already exists with same name.Please select another image .'); | |
return false; | |
else: | |
$this->create_resized_for_module($type, $image_name); | |
return true; | |
endif; | |
else: | |
if (file_put_contents($img, file_get_contents($url))): | |
if (file_exists(DIR_FS_SITE_UPLOAD . 'photo/' . $type . '/thumb/' . $image_name)): | |
$admin_user->set_pass_msg('Image already exists with same name.Please select another image .'); | |
return false; | |
else: | |
$this->create_resized_for_module($type, $image_name); | |
return true; | |
endif; | |
else: | |
return false; | |
endif; | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment