[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
Fri Mar 26 02:53:16 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:     
-------------------------+--------------------------------------------------
Changes (by nacin):

  * component:  General => Media
  * milestone:  Unassigned => 3.1


Old description:

> It's useful to get all the data relating to an image via one source:
>
> /**
> * returns an array containing attributes for an image stored in the
> database
>  * $image_id : id of the image to query
>  * $size : size of the image, can be 'thumbnail', 'medium', 'large' or
> 'full'
>  */
> function get_image_by_id($image_id, $size) {
>         $image = get_post($image_id);
>
>         $imageObj = array();
>         $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;
> }

New description:

 It's useful to get all the data relating to an image via one source:
 {{{
 /**
 * returns an array containing attributes for an image stored in the
 database
  * $image_id : id of the image to query
  * $size : size of the image, can be 'thumbnail', 'medium', 'large' or
 'full'
  */
 function get_image_by_id($image_id, $size) {
         $image = get_post($image_id);

         $imageObj = array();
         $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;
 }
 }}}

--

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


More information about the wp-trac mailing list