Created
March 15, 2019 08:57
-
-
Save mafsdisseny/d6038d84bf4df5038417fd29feb96103 to your computer and use it in GitHub Desktop.
Función que redimensiona las imágenes grandes al subirlas al sistema. Source: https://ayudawp.com/redimensionar-imagenes-grandes/
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 | |
/** Redimensionar al subir la imagen completa al tamaño grande de los ajustes de medios */ | |
/** SOURCE: https://ayudawp.com/redimensionar-imagenes-grandes/ */ | |
function ayudawp_reemplazar_imagen_subida($image_data) { | |
// si no hay imagen grande : return | |
if (!isset($image_data['sizes']['large'])) | |
return $image_data; | |
// ruta a la imagen subida y a la imagen grande | |
$upload_dir = wp_upload_dir(); | |
$uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file']; | |
$large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file']; | |
// borramos la imagen subida | |
unlink($uploaded_image_location); | |
// renombramos la imagen grande | |
rename($large_image_location,$uploaded_image_location); | |
// actualizamos los metadatos de la imagen y terminamos | |
$image_data['width'] = $image_data['sizes']['large']['width']; | |
$image_data['height'] = $image_data['sizes']['large']['height']; | |
unset($image_data['sizes']['large']); | |
return $image_data; | |
} | |
add_filter('wp_generate_attachment_metadata','ayudawp_reemplazar_imagen_subida'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment