Skip to content

Instantly share code, notes, and snippets.

@EliuTimana
Created September 13, 2015 22:26
Show Gist options
  • Save EliuTimana/b358e718963845365129 to your computer and use it in GitHub Desktop.
Save EliuTimana/b358e718963845365129 to your computer and use it in GitHub Desktop.
<?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