Seguro que alguna vez te has preguntado, ¿cuál es el propósito del programador de tareas de Windows? Si eres de…
function resize_image_safe($filepath, $new_width = 1200) { // Intentar redimensionar con el editor WP $editor = wp_get_image_editor($filepath); if (is_wp_error($editor)) { error_log("WP Editor no disponible para $filepath: " . $editor->get_error_message()); return resize_image_with_imagick_forced($filepath, $new_width); } $size = $editor->get_size(); if (!$size || empty($size['width']) || empty($size['height'])) { error_log("No se pudieron obtener dimensiones para $filepath"); return resize_image_with_imagick_forced($filepath, $new_width); } try { $editor->resize($new_width, 0); $saved = $editor->save($filepath); if (is_wp_error($saved)) { error_log("Error al guardar imagen redimensionada $filepath: " . $saved->get_error_message()); return resize_image_with_imagick_forced($filepath, $new_width); } return true; } catch (Exception $e) { error_log("Excepción en wp_get_image_editor para $filepath: " . $e->getMessage()); return resize_image_with_imagick_forced($filepath, $new_width); } } // Función fallback con Imagick forzado function resize_image_with_imagick_forced($filepath, $new_width = 1200) { if (!class_exists('Imagick')) { error_log("Imagick no está disponible para forzar redimensionado de $filepath"); return false; } try { $im = new Imagick($filepath); // Obtener tamaño original para cálculo proporcional $orig_width = $im->getImageWidth(); $orig_height = $im->getImageHeight(); if (!$orig_width || !$orig_height) { error_log("Imagick no pudo obtener dimensiones de $filepath"); return false; } $new_height = intval($orig_height * ($new_width / $orig_width)); $im->resizeImage($new_width, $new_height, Imagick::FILTER_LANCZOS, 1); // Sobrescribir archivo original (puedes cambiar a otro path si quieres) $im->writeImage($filepath); $im->clear(); $im->destroy(); return true; } catch (Exception $e) { error_log("Error al redimensionar con Imagick para $filepath: " . $e->getMessage()); return false; } }
Seguro que alguna vez te has preguntado, ¿cuál es el propósito del programador de tareas de Windows? Si eres de…