I’ve integrated the WordPress database directly with my .NET application.
What I want is to set the featured image of a post. This featured image must be maximum 800pixels wide, and automatically sized to that width (keeping the correct width/height ratio).
Medium size
is set tp 300×300
Large size
is set to 1024×1024
What I did now is go to Settings > Media
and set the width of Thumbnail size
to 600 and unchecked the checkbox Crop thumbnail to exact dimensions (normally thumbnails are proportional)
.
Now when I upload a new featured image, where can I find the filename of the image with a width of 600px and how can I retrieve it via SQL?
UPDATE
I see these rows in [wp_postmeta]
meta_id post_id meta_key meta_value
76 16 _wp_attached_file 2014/01/sitelargeblah.png
77 16 _wp_attachment_metadata a:5:{s:5:"width";i:1920;s:6:"height";i:1643;s:4:"file";s:25:"2014/01/sitelargeblah.png";s:5:"sizes";a:4:{s:9:"thumbnail";a:4:{s:4:"file";s:25:"sitelargeblah-175x150.png";s:5:"width";i:175;s:6:"height";i:150;s:9:"mime-type";s:9:"image/png";}s:6:"medium";a:4:{s:4:"file";s:25:"sitelargeblah-300x256.png";s:5:"width";i:300;s:6:"height";i:256;s:9:"mime-type";s:9:"image/png";}s:5:"large";a:4:{s:4:"file";s:26:"sitelargeblah-1024x876.png";s:5:"width";i:1024;s:6:"height";i:876;s:9:"mime-type";s:9:"image/png";}s:14:"post-thumbnail";a:4:{s:4:"file";s:25:"sitelargeblah-604x270.png";s:5:"width";i:604;s:6:"height";i:270;s:9:"mime-type";s:9:"image/png";}}s:10:"image_meta";a:10:{s:8:"aperture";i:0;s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";i:0;s:9:"copyright";s:0:"";s:12:"focal_length";i:0;s:3:"iso";i:0;s:13:"shutter_speed";i:0;s:5:"title";s:0:"";}}
I see the 300px width and the 1024px width, but no 800px width of the thumbnail. Why not?
I can not simply append 800×800 after the value in _wp_attached_file
, since the resized image is not an exact square, but with dimensions ratios preserved.
In the post meta you can find the, attachment ID, you need lockup the org file name, and then ether loop throw the images sizes (In the meta data of the attachment) or append -600×600 to the file name if upload and image bigger then 600.