Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'wp_generate_attachment_metadata', 'replace_uploaded_image' );
- function replace_uploaded_image($image_data)
- {
- // abortar se não houver versão "large" da imagem
- if ( !isset($image_data['sizes']['large']) )
- return $image_data;
- // paths do upload e da imagem 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'];
- // deletar original
- unlink($uploaded_image_location);
- // renomear a imagem "large"
- rename($large_image_location, $uploaded_image_location);
- // atualizar o metadata da imagem e retornar
- $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_image_size( 'new-large', 1600, 1200 );
Add Comment
Please, Sign In to add comment