I am not sure how you can grab the size from the core of WP but I think that when a user enters a size of the image in the field it adds a style tag to the <img tag and this is where it gets its size. I am not sure how it works completely .
Are you developing a plugin that hooks into this feature?
Well, it’s sort of a plugin. I have a custom function to create custom meta boxes dynamically. All you have to do is create an array… my function loops through the array and creates a table of meta box form fields.
One of the options you can use is “photo” which basically creates a button on the page to allow you to open the built in Media Uploader in a thichbox. You can select an image from there, and it will place the id of that image in a hidden field, but show the image itself in the meta box as a preview.
Since the javascript code only gets the path to the original image (which is what I want), I need the javascript to also be able to add a width and height attribute to the “preview” image when it inserts it… to keep it nicely formatted. When the page loads, PHP handles that piece, so no need to worry about that.
Again, my solution above is working, and I’m getting the values. I’m just not sure it’s the best approach and am looking for suggestions.
Yeah, pretty interesting stuff. I’d be willing to share the information with anyone who’s interested. But before I do, I’d like to know that I’m doing it a clean and effective way. Anyone?
foreach (get_intermediate_image_sizes() as $s) {
if (isset($_wp_additional_image_sizes[$s])) {
$width = intval($_wp_additional_image_sizes[$s]['width']);
$height = intval($_wp_additional_image_sizes[$s]['height']);
} else {
$width = get_option($s.'_size_w');
$height = get_option($s.'_size_h');
}
}
get_intermediate_image_sizes() is a built-in wordpress function that gets all registered image sizes. however, the height/width of the built-in sizes (defined on the media settings page) are stored differently than the dimensions of theme-defined sizes. hence the if/else.
you may have to add:
global $_wp_additional_image_sizes
best of luck.
This is exactly what I needed!!! Thanks so much.
When using my code above, I would have to change the table name from site to site… a bit of a nuisance. But with your code, I can add this to my core functionslib.php (my additional functions.php file for functions that never change and are used in all our sites) for all future WordPress sites!!!
Again, thanks so much for helping.