[wp-trac] [WordPress Trac] #12238: image helper functions that I think would be useful in the core

WordPress Trac wp-trac at lists.automattic.com
Thu Jun 10 14:53:47 UTC 2010


#12238: image helper functions that I think would be useful in the core
-------------------------+--------------------------------------------------
 Reporter:  jredfern     |       Owner:     
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  3.1
Component:  Media        |     Version:     
 Severity:  normal       |    Keywords:     
-------------------------+--------------------------------------------------

Comment(by alexmansfield):

 I wish I would have found this earlier. It is so much simpler than the
 solution I was working on. However, think it would helpful to be able to
 access the data in an object format $object->variable. Also, setting a
 default value for $size would allow easier access to image details such as
 caption and description when the size doesn't matter. Here are the changes
 I made:

 {{{
 function get_image_by_id($image_id, $size = 'full') {
         $image = get_post($image_id);
         $imagearray = wp_get_attachment_image_src($image->ID, $size,
 false);
         $imageObj->src = $imagearray[0];
         $imageObj->width = $imagearray[1];
         $imageObj->height = $imagearray[2];
         $imageObj->id = $image->ID;
         $imageObj->title = $image->post_title;
         $imageObj->caption = $image->post_excerpt;
         $imageObj->description = $image->post_content;
         $imageObj->alt = get_post_meta($image->ID,
 '_wp_attachment_image_alt', true);

         return $imageObj;
 }
 }}}

 Let me know if there's anything else I can do to help this process along.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12238#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list