Ejemplo n.º 1
0
 function wp_img_resizer($args = '', $attr = '')
 {
     // set to get an array
     if (!isset($args['single'])) {
         $args['single'] = FALSE;
     }
     // set for an default echo if img tag
     if (!isset($args['echo'])) {
         $args['echo'] = TRUE;
     }
     $image = wp_img_resizer_src($args);
     list($image[0], $image[1], $image[2]) = $image;
     $hwstring = image_hwstring($image[1], $image[2]);
     // set defaults
     $default_attr = array('src' => $image[0], 'class' => "attachment-{$image[1]}x{$image[2]}", 'alt' => trim(strip_tags(get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', TRUE))), 'title' => trim(strip_tags(get_the_title())));
     if (empty($default_attr['alt'])) {
         $default_attr['alt'] = trim(strip_tags(get_the_excerpt()));
     }
     // If not, Use the Caption
     if (empty($default_attr['alt'])) {
         $default_attr['alt'] = trim(strip_tags(get_the_title()));
     }
     // Finally, use the title
     $attr = wp_parse_args($attr, $default_attr);
     $attr = array_map('esc_attr', $attr);
     // build img-Tag with attributes
     $html = rtrim('<img ' . $hwstring);
     foreach ($attr as $name => $value) {
         $html .= ' ' . $name . '=' . '"' . $value . '"';
     }
     $html .= ' />';
     if ($args['echo']) {
         echo $html;
     }
     if (!$args['echo']) {
         return $html;
     } else {
         return null;
     }
 }
Ejemplo n.º 2
0
 function automobile_resize($url = '', $width = '', $height = NULL, $crop = NULL, $single = TRUE)
 {
     if (empty($url)) {
         return NULL;
     }
     if (empty($width)) {
         return NULL;
     }
     $args = array('url' => $url, 'width' => $width, 'height' => $height, 'crop' => $crop, 'single' => $single);
     return wp_img_resizer_src($args);
 }