[wp-trac] [WordPress Trac] #44609: Different metadata and sizes coming when uploaded via media library and wp_insert_attachment()

WordPress Trac noreply at wordpress.org
Thu Jul 19 04:15:55 UTC 2018


#44609: Different metadata and sizes coming when uploaded via media library and
wp_insert_attachment()
--------------------------+-----------------------------
 Reporter:  dipakbbsr     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  4.9.7
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 My frontend requires a specific size for the Image Custom Field for a
 Custom Taxonomy. When Term is created at backend and image is added via
 Media Library, the size comes perfectly.

 But when Term and Term image is added from a custom form ( Tried both
 custom PHP coding https://rudrastyh.com/wordpress/how-to-add-images-to-
 media-library-from-uploaded-files-programmatically.html and ACF Pro image
 field ) the size is coming different.

 I tried checking the metadata for two Attachment Posts and their thumbnail
 sizes seems to be different.

 I am adding the serialised meta data here, 1st one is when added from
 admin, 2nd one is when added from custom form.


 {{{
 a:5:{s:5:"width";s:3:"696";s:6:"height";s:3:"400";s:4:"file";s:25:"2018/01/bathbodyworks.jpg";s:5:"sizes";a:5:{s:9:"thumbnail";a:4:{s:4:"file";s:25
 :"bathbodyworks-
 150x150.jpg";s:5:"width";s:3:"150";s:6:"height";s:3:"150";s:9:"mime-
 type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:4:"file";s:25:"bathbodyworks-
 300x172.jpg";s:5:"width";s:3:"300";s:6:"height";s:3:"172";s:9:"mime-
 type";s:10:"image/jpeg";}s:20:"wpcoupon_small_thumb";a:4:{s:4:"file";s:25
 :"bathbodyworks-
 200x115.jpg";s:5:"width";s:3:"200";s:6:"height";s:3:"115";s:9:"mime-
 type";s:10:"image/jpeg";}s:21:"wpcoupon_medium-thumb";a:4:{s:4:"file";s:25
 :"bathbodyworks-
 480x276.jpg";s:5:"width";s:3:"480";s:6:"height";s:3:"276";s:9:"mime-
 type";s:10:"image/jpeg";}s:20:"wpcoupon_blog_medium";a:4:{s:4:"file";s:25
 :"bathbodyworks-
 620x300.jpg";s:5:"width";s:3:"620";s:6:"height";s:3:"300";s:9:"mime-
 type";s:10:"image/jpeg";}}s:10:"image_meta";a:11:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";}}
 }}}



 {{{
 a:5:{s:5:"width";i:696;s:6:"height";i:400;s:4:"file";s:27:"2018/07/bath-
 body-works.jpg";s:5:"sizes";a:7:{s:9:"thumbnail";a:4:{s:4:"file";s:27
 :"bath-body-works-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9
 :"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:4:"file";s:27:"bath-
 body-works-300x300.jpg";s:5:"width";i:300;s:6:"height";i:300;s:9:"mime-
 type";s:10:"image/jpeg";}s:12:"medium_large";a:4:{s:4:"file";s:27:"bath-
 body-works-768x441.jpg";s:5:"width";i:768;s:6:"height";i:441;s:9:"mime-
 type";s:10:"image/jpeg";}s:5:"large";a:4:{s:4:"file";s:29:"bath-body-
 works-1024x1024.jpg";s:5:"width";i:1024;s:6:"height";i:1024;s:9:"mime-
 type";s:10:"image/jpeg";}s:20:"wpcoupon_small_thumb";a:4:{s:4:"file";s:27
 :"bath-body-works-200x115.jpg";s:5:"width";i:200;s:6:"height";i:115;s:9
 :"mime-type";s:10:"image/jpeg";}s:21:"wpcoupon_medium-
 thumb";a:4:{s:4:"file";s:27:"bath-body-works-
 480x480.jpg";s:5:"width";i:480;s:6:"height";i:276;s:9:"mime-
 type";s:10:"image/jpeg";}s:20:"wpcoupon_blog_medium";a:4:{s:4:"file";s:27
 :"bath-body-works-620x300.jpg";s:5:"width";i:620;s:6:"height";i:300;s:9
 :"mime-
 type";s:10:"image/jpeg";}}s:10:"image_meta";a:12:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";s:8:"keywords";a:0:{}}}
 }}}

 While the 1st one creates a medium size of 300x172, 2nd one is generating
 with 300x300.

 Am i missing something that does not creating exact metadata as Media
 Library ?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44609>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list