Created
September 13, 2015 22:26
-
-
Save EliuTimana/b358e718963845365129 to your computer and use it in GitHub Desktop.
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
<?php | |
function thumbnail($path){ | |
list($ancho, $alto) = getimagesize($path); | |
$nuevo_ancho = $nuevo_alto = 150; | |
$ext = '.'.pathinfo($path, PATHINFO_EXTENSION); | |
$name = pathinfo($path, PATHINFO_FILENAME); | |
$dir = pathinfo($path, PATHINFO_DIRNAME); | |
$thumb = imagecreatetruecolor($nuevo_ancho, $nuevo_alto); | |
if($ext == '.png' || $ext == '.PNG') $origen = imagecreatefrompng($path); | |
if($ext == '.jpg' || $ext == '.JPG' || $ext == '.JPEG' || $ext == '.jpeg') $origen = imagecreatefromjpeg($path); | |
if($ext == '.gif' || $ext == '.GIF') $origen = imagecreatefromgif($path); | |
imagecopyresized($thumb, $origen, 0, 0, 0, 0, $nuevo_ancho, $nuevo_alto, $ancho, $alto); | |
$ruta_final = $dir.'/'.$name.'_thumb'.$ext; | |
if($ext == '.png' || $ext == '.PNG'){ | |
imagepng($thumb, $ruta_final); | |
}else{ | |
if($ext == '.jpg' || $ext == '.JPG' || $ext == '.JPEG' || $ext == '.jpeg'){ | |
imagejpeg($thumb, $ruta_final); | |
}else{ | |
if($ext == '.gif' || $ext == '.GIF'){ | |
imagegif($thumb, $ruta_final); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment