2

I am creating a parser that is parsing an XML file and uploading an image to media library. Everything works fine.

But after uploading, the different image as per Media Settings are also generated. For eg: Medium, Thumbnail etc.

I want to stop generating the duplicate image of different size only to those images ( images that are uploaded from parsing ). Is that possible?

require_once( ABSPATH . 'wp-admin/includes/image.php' );
$filetype = wp_check_filetype( basename( $uploadfile ), null );

$attachment = array(
    'guid'           => basename( $uploadfile ),
    'post_mime_type' => $filetype['type'],
    'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $uploadfile ) ),
    'post_content'   => '',
    'post_status'    => 'inherit',
);

$attach_id   = wp_insert_attachment( $attachment, $uploadfile );

$attach_data = wp_generate_attachment_metadata( $attach_id, $uploadfile );

wp_update_attachment_metadata( $attach_id, $attach_data );

return $attach_id;
0

We can't do this. As simple as that

  • Wrong. You can add/remove image sizes. Remove the image sizes during this parser, and they won't be recognized as image sizes in the system during this process. – Eric Holmes Sep 29 '16 at 13:28
  • yes. so how I can do this.. I was trying by doing remove_filter( 'intermediate_image_sizes' ); but did not worked – Aftab Sep 29 '16 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.