Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Has anyone used the php image resample


wra77877

Recommended Posts

i found the miracle solution to my problem...except now when i enlarge the image it is distorted...

 

i use one large image for the enlarge pic and thumbnail pic...so before the thumbnail pic was distorted...i found the php image resample contribution and it fixed the thumbnail perfect..however now when i use the image amplification contribution to go with it, it will distor the large image...anyone familiar with these 2 or can someone help fix the javascripts...

 

this is what i added to the functions/html_output and it fixed my thumbnails....

 

function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '')

{

// if no width or height specified or file not found use default function

if ((!$width) || (!$height) || (!is_file(DIR_FS_CATALOG . '/' . $src)))

return tep_default_image($src, $alt, $width, $height, $parameters);

 

// Name for the resampled image (always JPEG for decent results in size and quality

$newName = eregi_replace( '\.([a-z]{3,4})', "-{$width}x{$height}.jpg", $src );

 

// if resampled image exists, no need to create. Use existing one.

// Added check to determine whether thumbnail is older than main image. If it is, the main image has been updated. Generate a new thumbnail. -- Greg Bolshaw

if( is_file( DIR_FS_CATALOG . '/' . $newName ) && filemtime( DIR_FS_CATALOG . '/' . $src ) < filemtime ( DIR_FS_CATALOG . '/' . $newName) )

{

$src = $newName;

return tep_default_image($src, $alt, $width, $height, $parameters);

}

 

// get the size of the image. if width or height=0, image is broken. No processing.

$size = GetImageSize(DIR_FS_CATALOG . '/' . $src);

if (!$size[0] || !$size[1])

return tep_default_image($src, $alt, $width, $height, $parameters);

 

// Calculate Scaling Factor and x,y pos for centering the thumbnail

// If scale = 1, image does not need to be resized.

$scale = min($width/$size[0], $height/$size[1]);

if ( $scale == 1 )

return tep_default_image($src, $alt, $width, $height, $parameters);

 

$newwidth = (int)($size[0]*$scale);

$newheight = (int)($size[1]*$scale);

$xpos = (int)(($width - $newwidth)/2);

$ypos = (int)(($height - $newheight)/2);

 

//create the destination image resource.

//always use true color here, or you'll get some real bad color shifts

$destImg = ImageCreateTrueColor($width, $height);

$backColor=ImageColorAllocate($destImg, 255, 255, 255);

ImageFilledRectangle($destImg, 0, 0, $width, $height, $backColor);

 

// Check image format. Only process JPG or PNG. GIF not supported by PHP.

// The results with gifs were no good anyway

switch ( $size[2] )

{

case 2: // JPG

$sourceImg = ImageCreateFromJPEG (DIR_FS_CATALOG . '/' . $src);

if (function_exists('ImageCopyResampled'))

ImageCopyResampled($destImg, $sourceImg, $xpos, $ypos, 0, 0, $newwidth, $newheight, $size[0], $size[1]);

else

ImageCopyResized($destImg, $sourceImg, $xpos, $ypos, 0, 0, $newwidth, $newheight, $size[0], $size[1]);

imagejpeg($destImg, DIR_FS_CATALOG . '/' . $newName, 90);

$src = $newName; // Use the resampled image

$width = $height = ""; // and it's own properties

break;

case 3: // PNG

$sourceImg = ImageCreateFromPNG (DIR_FS_CATALOG . '/' . $src);

if (function_exists('ImageCopyResampled'))

ImageCopyResampled($destImg, $sourceImg, $xpos, $ypos, 0, 0, $newwidth, $newheight, $size[0], $size[1]);

else

ImageCopyResized($destImg, $sourceImg, $xpos, $ypos, 0, 0, $newwidth, $newheight, $size[0], $size[1]);

imagejpeg($destImg, DIR_FS_CATALOG . '/' . $newName, 90);

$src = $newName;

$width = $height = "";

break;

}

return tep_default_image($src, $alt, $width, $height, $parameters);

}

 

 

this is the javasrpript for the amplification factor to make the thumbnail enlarge(this is where the distort takes place)

 

<script language="javascript"><!--

function smallbig() {

var smallwidth = <?php echo SMALL_IMAGE_WIDTH; ?>;

var smallheight = <?php echo SMALL_IMAGE_HEIGHT; ?>;

//Set the amplificationfactor:

amplificationfactor = 4.0;

var largewidth = amplificationfactor * smallwidth;

var largeheight = amplificationfactor * smallheight;

if (document.image1.width == smallwidth) {

document.image1.width=largewidth;document.image1.height=largeheight;}

else {

document.image1.width=smallwidth;document.image1.height=smallheight;}

}

//--></script>

 

any suggestions or help would be great...i know i can count on someone theres alot of smart people in these rooms...thanks, bill

Link to comment
Share on other sites

i use one large image for the enlarge pic  and thumbnail pic...so before the thumbnail pic was distorted...i found the php image resample contribution and it fixed the thumbnail perfect..however now when i use the image amplification contribution to go with it, it will distor the large image...anyone familiar with these 2 or can someone help fix the javascripts...

 

I used these as well, what i did to fix the same problems was go into configurations and then images in the admin control panel and changed all the heights to 0 and then the widths at what i wanted them to be, then true for calculate image size, image amplification, and constrain proportions. This is what worked for me, now my images come out just beautifully. THe only drawback is that that your thumbnails are not all the same size and uniform looking, as they would be in specifying both height and width, but this doesn't matter to me, my pics looking as they should - definately does!

 

Hope this helps! Good luck

Link to comment
Share on other sites

I used these as well, what i did to fix the same problems was go into configurations and then images in the admin control panel and changed all the heights to 0 and then the widths at  what i wanted them to be, then true for calculate image size, image amplification, and constrain proportions.  This is what worked for me, now my images come out just beautifully.  THe only drawback is that that your thumbnails are not all the same size and uniform looking, as they would be in specifying both height and width, but this doesn't matter to me, my pics looking as they should - definately does!

 

Hope this helps!  Good luck

 

not working for me

maybe im doing something wrong...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...