Created
May 2, 2018 18:18
-
-
Save danilobatistaqueiroz/1f760d8f7547e554e9eed49563c9fbf7 to your computer and use it in GitHub Desktop.
Php Snippets
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
<?php | |
function compress_image($source_url, $destination_url, $quality) | |
{ | |
$info = getimagesize($source_url); | |
if ($info['mime'] == 'image/jpeg') { | |
$image = imagecreatefromjpeg($source_url); | |
} elseif ($info['mime'] == 'image/gif') { | |
$image = imagecreatefromgif($source_url); | |
} elseif ($info['mime'] == 'image/png') { | |
$image = imagecreatefrompng($source_url); | |
} | |
imagepng($image, $destination_url, $quality); | |
return $destination_url; | |
} | |
$url = __DIR__.DIRECTORY_SEPARATOR."imagem_comprimida.png"; | |
$filename = compress_image($_FILES["file1"]["tmp_name"], $url, 8); | |
?> | |
<form action="compressing_images.php" name="myform" id="myform" method="post" enctype="multipart/form-data"> | |
<input type="file" name="file1" id="file1" /> | |
<input type="submit" value="enviar" /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment