Created
February 12, 2018 16:18
-
-
Save melissacabral/e0f9a1fd5da852050d93889f9edfa806 to your computer and use it in GitHub Desktop.
Change the image uploader we built so that it preserves the original aspect ratio. Replaces lines in the foreach($sizes) loop. Prevents up-sampling
This file contains 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
if($width >= $pixels){ | |
//wider than desired size | |
$newwidth = $pixels; | |
//calculate the correct height | |
$newheight=($height/$width) * $newwidth; | |
}else{ | |
//smaller than desired size. preserve original width and height | |
$newwidth=$width; | |
$newheight=$height; | |
} | |
$tmp_canvas = imagecreatetruecolor($newwidth,$newheight); | |
imagecopyresampled($tmp_canvas,$src,0,0,0,0,$newwidth,$newheight,$width,$height); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment