Skip to content

Instantly share code, notes, and snippets.

@helisoncruz
Created February 14, 2020 00:19
Show Gist options
  • Save helisoncruz/11eb67b634039da77d243afd0cff60a5 to your computer and use it in GitHub Desktop.
Save helisoncruz/11eb67b634039da77d243afd0cff60a5 to your computer and use it in GitHub Desktop.
Upload de Arquivos Simples
<?php
function upload_jpg($tmp,$novo_nome,$largura,$pasta){
$img = imagecreatefromjpeg($tmp);
$x = imagesx($img);
$y = imagesy($img);
$altura = ($largura*$y) / $x;
$nova_imagem = imagecreatetruecolor($largura,$altura);
imagecopyresampled($nova_imagem,$img,0,0,0,0,$largura,$altura,$x,$y);
imagejpeg($nova_imagem,"$pasta/$novo_nome",100);
imagedestroy($nova_imagem);
imagedestroy($img);
return($novo_nome);
}
function upload_png($tmp,$novo_nome,$largura,$pasta){
$img = imagecreatefrompng($tmp);
$x = imagesx($img);
$y = imagesy($img);
$altura = ($largura*$y) / $x;
$nova_imagem = imagecreatetruecolor($largura,$altura);
imagecopyresampled($nova_imagem,$img,0,0,0,0,$largura,$altura,$x,$y);
imagejpeg($nova_imagem,"$pasta/$novo_nome",100);
imagedestroy($nova_imagem);
imagedestroy($img);
return($novo_nome);
}
function upload_gif($tmp,$novo_nome,$largura,$pasta){
$img = imagecreatefromgif($tmp);
$x = imagesx($img);
$y = imagesy($img);
$altura = ($largura*$y) / $x;
$nova_imagem = imagecreatetruecolor($largura,$altura);
imagecopyresampled($nova_imagem,$img,0,0,0,0,$largura,$altura,$x,$y);
imagejpeg($nova_imagem,"$pasta/$novo_nome",100);
imagedestroy($nova_imagem);
imagedestroy($img);
return($novo_nome);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment