Guest User

Untitled

a guest
Nov 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. add_filter( 'wp_generate_attachment_metadata', 'replace_uploaded_image' );
  2.  
  3. function replace_uploaded_image($image_data)
  4. {
  5. // abortar se não houver versão "large" da imagem
  6. if ( !isset($image_data['sizes']['large']) )
  7. return $image_data;
  8.  
  9. // paths do upload e da imagem grande
  10. $upload_dir = wp_upload_dir();
  11. $uploaded_image_location = $upload_dir['basedir'] . '/' . $image_data['file'];
  12. $large_image_location = $upload_dir['path'] . '/' . $image_data['sizes']['large']['file'];
  13.  
  14. // deletar original
  15. unlink($uploaded_image_location);
  16.  
  17. // renomear a imagem "large"
  18. rename($large_image_location, $uploaded_image_location);
  19.  
  20. // atualizar o metadata da imagem e retornar
  21. $image_data['width'] = $image_data['sizes']['large']['width'];
  22. $image_data['height'] = $image_data['sizes']['large']['height'];
  23. unset($image_data['sizes']['large']);
  24.  
  25. return $image_data;
  26. }
  27.  
  28. add_image_size( 'new-large', 1600, 1200 );
Add Comment
Please, Sign In to add comment