Answer the question
In order to leave comments, you need to log in
Image resizing on the fly with WordPress?
Good afternoon!
I'm trying to change the image on the fly, using standard WordPress tools (without saving the thumbnail image). Having studied the code, I found a function that does this:
<?php
// загружаем объект
$image = wp_get_image_editor( 'http://wp-kama.ru/wp-content/uploads/2014/02/uka.png' );
// обрабатываем картинку
if ( ! is_wp_error( $image ) ) {
// уменьшим её до размеров 80х80
$image->resize( 80, 80, true );
// сохраним в корне сайта под названием new_image.png
$image->save( $_SERVER['DOCUMENT_ROOT'].'/new_image.png' );
}
?>
<?php
$image = wp_get_image_editor( 'http://wp-kama.ru/wp-content/uploads/2014/02/uka.png' );
if ( ! is_wp_error( $image ) ) {
$image->resize( 80, 80, true );
?>
<img src="<?php echo $image; ?>">
<?php } ?>
Answer the question
In order to leave comments, you need to log in
wp_get_image_editor() requires a local image path , not a url. The URL may work, but not always - it depends on the server. Look at the $image dump, it's not a fact that the image from the remote server arrived in WP_Image_Editor and it was correctly initialized.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question