Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

auto resize images - occasionally adding borders


Guest

Recommended Posts

Hi,

 

I've installed the contrib 'auto resize images'. It works very well, but it randomly adds a 1px black border to some of the images.

 

It changes the tep_image function to use mogrify in the includes/functions/http_output.php file. Here's the code:

  function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '', $res = 1, $addattribs = 1){
if ((empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') || !is_file($src)) {
  return false;
} 
if ( !strstr($width, '%') && $res) {
  $width = round($width);
  $height = round($height);
  preg_match("/.*\/(.*)\.(\w*)$/", $src, $fname);
  list($oiwidth, $oiheight, $oitype) = getimagesize($src);
  if (($width || $height) && ($height < $oiheight || $width < $oiwidth)) {
	if (!$height) $height = 1;
	if (!$width) $width = 1;
	$k = max($oiheight / $height, $oiwidth / $width); //use smallest size
	$width = round($oiwidth / $k);
	$height = round($oiheight / $k); 
	// createthumb($filename, $width, $height, "test.jpg");
	$filename_small = DIR_WS_RSIMAGES . $fname[1] . '_' . $width . '_' . $height . '.' . $fname[2];
	if (!file_exists($filename_small)) {
	  copy($src, $filename_small);
	  exec(DIR_IMAGEMAGICK . "mogrify -geometry " . $width . " " . $filename_small);
	} 
	$src = $filename_small;
  } 
} 
// alt is added to the img tag even if it is null to prevent browsers from outputting
// the image filename as default
$image = '<img src="' . tep_output_string($src) . '" border="0" alt="' . tep_output_string($alt) . '"';

if (tep_not_null($alt)) {
  $image .= ' title=" ' . tep_output_string($alt) . ' "';
} 

if ($addattribs && tep_not_null($width) && tep_not_null($height)) {
  $image .= ' width="' . tep_output_string($width) . '" height="' . tep_output_string($height) . '"';
} 

if (tep_not_null($parameters)) $image .= ' ' . $parameters;

$image .= '>';

return $image;
 }

 

Any ideas???

Link to comment
Share on other sites

Damn the inability to edit posts!!

 

I've temporarily fixed it by adding -bordercolour white to the mogrify command. This only works while the bg is white (it may not be soon) I tried border 0x0 but it still left a slight border for some reason.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...