Skip to content

Instantly share code, notes, and snippets.

@mafsdisseny
Created March 15, 2019 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mafsdisseny/d6038d84bf4df5038417fd29feb96103 to your computer and use it in GitHub Desktop.
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/
<?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