Hi all,
I'm trying to modify a Wordpress theme to make it resize images into proportional thumbnails, to keep the same relative height / width of the original image - ideally to be displayed inside a 190px x 190px thumbnail box with letterboxing, if that's possible.
So far as I can tell, these are the bits of code that deal with the image display process - any help on how to tweak it to implement the above function would be much appreciated!:
[code=php] function product_listing_li_default($post,$args=array())
{
global $Product,$General,$thumb_url;
$image_width = $this->get_image_width($post->image_width);
$image_height = $this->get_image_height($post->image_height);
$product_image_arr = $this->get_product_image($post,'large','latest',1);
$attachment_id = $product_image_arr[0]['id'];
$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
$attach_data = get_post($attachment_id);
$title = $attach_data->post_title;
if($title ==''){ $title = $post->post_title; }
if($alt ==''){ $alt = $post->post_title; }
if($product_image_arr[0]){
$crop_image = $General->vt_resize($attachment_id, $product_image_arr[0]['file'], $image_width, $image_height, $crop = false );
$post_images = $crop_image['url'];
}
if($product_image_arr[0][0]==''){
$product_image= get_template_directory_uri().'/images/no-image.png';
}else{
$product_image = $post_images;
}
$is_image_border = 0;
if(is_category())
{
if(get_option('ptthemes_prdlstcatimage_border')){$is_image_border = 1;}
}elseif(is_home() && $_REQUEST['ptype']=='store')
{
if(get_option('ptthemes_prdlistimage_border')){$is_image_border = 1;}
}else
{
if(get_option('ptthemes_prdlsthomeimage_border')){$is_image_border = 1;}
}
$data = get_post_meta( $post->ID, 'key', true );
$product_price = $Product->get_product_price($post->ID);
/* width:<?php //echo $image_width;?>px; height:<?php// echo $image_height; */
?>
<a href="<?php echo get_permalink( $post->ID) ?>" class="product_thumb" style="width:<?php echo $image_width."px"; ?>; height:<?php echo $image_height."px"; ?>; overflow:hidden; <?php if($is_image_border){?>border:1px solid;<?php }?>" *>
<?php
if($Product->get_product_price_sale($post->ID)>0)
{
?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/sale.png" alt="" class="sale_img" />
<?php
}
$thumb_url .= $this->get_image_cutting_edge($args);
?> *<img src="<?php echo $product_image; ?>" *<?php if($is_image_border){?> border="1"<?php }?> width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>"/></a>
<?php
}
function get_image_height($image_height='')
{
if($image_height=='')
{
$image_height = get_option('ptthemes_image_height');
}
return $image_height;
}
function get_image_width($image_width='')
{
if($image_width=='')
{
$image_width = get_option('ptthemes_image_width');
}
return $image_width;
}
function product_listing_li_shorted($post,$display_order,$args=array())
{
global $Product,$General,$thumb_url;
$image_width = $this->get_image_width($post->image_width);
$image_height = $this->get_image_height($post->image_height);
$product_image_arr = $this->get_product_image($post,'large','shorted');
$attachment_id = $product_image_arr[0]['id'];
$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
$attach_data = get_post($attachment_id);
$title = $attach_data->post_title;
if($title ==''){ $title = $post->post_title; }
if($alt ==''){ $alt = $post->post_title; }
if($product_image_arr[0]){
$crop_image = $General->vt_resize($attachment_id, $product_image_arr[0]['file'], $image_width,$image_height, $crop = false );
$post_images = $crop_image['url'];
}
$data = get_post_meta( $post->ID, 'key', true );
$product_price = $Product->get_product_price($post->ID);
$content_strt_str ='';
$content_strt_end ='';
foreach($display_order as $key=>$val)
{
if($key=='image')
{
$is_image_border=0;
if(is_category())
{
if(get_option('ptthemes_prdlstcatimage_border')){$is_image_border = 1;}
}elseif(is_home() && $_REQUEST['ptype']=='store')
{
if(get_option('ptthemes_prdlistimage_border')){$is_image_border = 1;}
}else
{
if(get_option('ptthemes_prdlsthomeimage_border')){$is_image_border = 1;}
}
?>
<a href="<?php the_permalink() ?>" class="product_thumb" >
<?php if($Product->get_product_price_sale($post->ID)>0){?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/sale.png" alt="" class="sale_img" */>
<?php }?>
<?php $thumb_url .= $this->get_image_cutting_edge($args);?>
<img src="<?php echo $post_images;?>" alt="<?php the_title(); ?>" *<?php if($is_image_border){?> border="1"<?php }?> width="<?php echo $image_width; ?>" height="<?php echo $image_height; ?>"/></a>
function show_product_images($post)
{
global $thumb_url,$General;
//$product_image_arr = $this->get_product_image($pid);
$product_image_arr = $this->get_product_image($post,'large','detail');*
$image_width = apply_filters('ec_prd_detail_bimg_resize_filter',$image_width);
if($image_width==''){
$image_width =300; }
$image_height = apply_filters('ec_prd_detail_bimg_resize_hfilter',$image_height);
if($image_height==''){
$image_height = 300; }
$attachment_id = $product_image_arr[0]['id'];
$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
$attach_data = get_post($attachment_id);
$title = $attach_data->post_title;
if($title ==''){ $title = $post->post_title; }
if($alt ==''){ $alt = $post->post_title; }
if($product_image_arr[0][0]){
$crop_image = $General->vt_resize($attachment_id, $product_image_arr[0][0], $image_width, $image_height, $crop = false );
$post_images = $crop_image['url'];
}
if($product_image_arr)
{
*if($product_image_arr[0][0]){ ?> * * * **
<a class="zoom product_main_img" rel="group" title="" href="<?php echo $product_image_arr[0][0]; ?>" *>
<img src="<?php echo bloginfo('template_directory'); ?>/images/zoom.png" alt="" class="i_zoom" />
<img src="<?php echo $post_images;?>" alt="" />
</a>
<?php } ?>
<?php*
*if(count($product_image_arr)>1)
*{*
if(is_category())
{
if(get_option('ptthemes_prdlstcatimage_border')){$is_image_border = 1;}
}elseif(is_home() && $_REQUEST['ptype']=='store')
{
if(get_option('ptthemes_prdlistimage_border')){$is_image_border = 1;}
}else
{
if(get_option('ptthemes_prdlsthomeimage_border')){$is_image_border = 1;}
}
for($im=1;$im<count($product_image_arr);$im++)
{
$image_width1 = apply_filters('ec_prd_detail_timg_resize_filter',$image_width1);
if(!$image_width1){
$image_width1 = 100;
}
$image_height1 = apply_filters('ec_prd_detail_timg_resize_hfilter',$image_height1);
if(!$image_height1){
$image_height1 = 100;
}
$attachment_id = $product_image_arr[$im]['id'];
$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
$attach_data = get_post($attachment_id);
$title = $attach_data->post_title; if($title ==''){ $title = $post->post_title; }
$crop_image = $General->vt_resize($attachment_id, $product_image_arr[$im][0], $image_width1, $image_height1, $crop = false );
$post_images = $crop_image['url'];
$ext_arr = explode('.',$product_image_arr[$im][0]);
$fileext = strtolower($ext_arr[count($ext_arr)-1]);
if(in_array($fileext,array('jpg','jpeg','gif','png')))
{
?>
<a class="zoom smaller" rel="group" title="" href="<?php echo $product_image_arr[$im][0]; ?>"><img src="<?php echo $post_images; ?>" alt="<?php echo $alt; ?>" title="<?php echo $title; ?>" <?php if($is_image_border){?> border="1"<?php }?>/></a>
<?php
}
}
*}
*return true;
}else
{ ?>
<a class="zoom product_main_img" rel="group" title="" href="<?php echo $product_image_arr[0]; ?>" *>
<img src="<?php echo *get_template_directory_uri().'/images/no-image1.png'; ?><?php echo apply_filters('ec_prd_detail_bimg_resize_filter','&w=200&zc=1&q=80')?><?php echo $thumb_url;?>" alt="" />
</a>
<?php }
}
function get_image_cutting_edge($args=array())
{
if($args['image_cut'])
{
$cut_post =$args['image_cut'];
}else
{
$cut_post = get_option('ptthemes_image_x_cut');
}
if($cut_post)
{
if($cut_post=='top')
{
$thumb_url .= "&a=t";
}elseif($cut_post=='bottom')
{
$thumb_url .= "&a=b";
}elseif($cut_post=='left')
{
$thumb_url .= "&a=l";
}elseif($cut_post=='right')
{
$thumb_url .= "&a=r";
}elseif($cut_post=='top right')
{
$thumb_url .= "&a=tr";
}elseif($cut_post=='top left')
{
$thumb_url .= "&a=tl";
}elseif($cut_post=='bottom right')
{
$thumb_url .= "&a=br";
}elseif($cut_post=='bottom left')
{
$thumb_url .= "&a=bl";
}
}
return $thumb_url;
}
[/code]