Announcement

Collapse
No announcement yet.

Best Sellers / new product thumbs jagged!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by NormanRouxel View Post
    Here's how to amend that Advanced Guide article to do what you want.

    Create a folder within your Site folder called "Thumbnails".

    In your Mini Best Sellers Layout and Mini New Products Item, replace the line
    Code:
    <img style="border: 0;" src="<actinic:variable name="ProductImageFileName" />" width="75" alt="<actinic:variable name="ProductName" encoding="strip"/>" />
    with
    Code:
    	<actinic:block php="true" >
    	// START Create a thumbnail image t_nn_ProductImageFileName - V 1.04
    		$nScaledWidth = 75; 		// scaled image width
    		$sOriginalImageName = str_replace('\\','/', '<actinic:variable name="ProductImageFileName" encoding="perl" selectable="false" />');
    		$sThumbImageName = 'Thumbnails/t_' . $nScaledWidth . '_' . basename($sOriginalImageName);
    		list($width, $height, $imagetype, $imageattr) = getimagesize($sOriginalImageName);
    		switch ($imagetype) 
    			{
    			case 1:
    				$image = @imagecreatefromgif($sOriginalImageName); // Attempt to open GIF
    				break;
    			case 2:
    				$image = @imagecreatefromjpeg($sOriginalImageName); // Attempt to open JPG
    				break;
    			case 3:
    				$image = @imagecreatefrompng($sOriginalImageName); // Attempt to open PNG
    				break;
    			default:
    				$image = NULL;
    			}
    		if (!$image) 
    			{ // tell what failed
    			echo "<br><font color=red>Thumbnail creation error opening: $sOriginalImageName </font>";
    			}
    		else
    			{
    			// Get new dimensions
    			$t_width = $nScaledWidth;
    			$t_height = round($height * ($t_width / $width));
    			// Resample
    			$thumbimage = imagecreatetruecolor($t_width, $t_height);
    			imagecopyresampled($thumbimage, $image, 0, 0, 0, 0, $t_width, $t_height, $width, $height);
    			if ( ! imagejpeg($thumbimage, $sThumbImageName) ) 
    				{
    				echo "<font color=red>Thumbnail creation error saving: $sThumbImageName </font><br>";
    				}
    			else
    				{
    				echo "<img src=\"$sThumbImageName\" width=\"$t_width\" height=\"$t_height\" border=\"0\"";
    				echo ' alt="' . htmlspecialchars('<actinic:variable name="ProductName" encoding="perl" selectable="false" />') . '" />';
    				}	
    			}
     	// END Create a thumbnail image t_nn_ProductImageFileName
     	</actinic:block>
    Change the line

    $nScaledWidth = 75; // scaled image width

    to suit the width you want.
    This helped me a ton, the old php script from the downloaded advanced manual broke with the upgrade to v9, this one works a charm!
    Regards,
    Simon Dann Ba Hons, MA.

    "The markings of a great platform is it not forcing its users to hack around it, but to progress logically through it" - Anon

    Comment

    Working...
    X