php - How to save two copies of the same image in a wordpress upload? -


so here's i'm trying do, when users upload new image, want make image half size (keeping proportion) , half resolution, save both versions. maybe save original 'image-upload.jpg' , 1 modify using php save 'image-upload-halved.jpg'

i've messed around wordpress filters, can't seem it. below along lines of thinking should do, have no idea.

add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );  function custom_upload_filter( $file ){     // here hoping image manipulation     // , save both versions of image } 

any advice or links other wordpress filters might fit job better awesome, too.

thanks!

take @ documentation add_image_size https://developer.wordpress.org/reference/functions/add_image_size/

you should able add new image size this:

add_image_size( 'custom-size', 220, 180 ); // 220 pixels wide 180 pixels tall, soft proportional crop mode 

replace "custom-size" name size , pixel values want.

you can call image in template this:

// assuming media library image has post id of 42... echo wp_get_attachment_image( 42, 'your-custom-size' ); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -