Announcement

Collapse
No announcement yet.

Error for php resize images script

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

    Error for php resize images script

    I am trying to use a php script in the advanced user guide, which automatically resizes the product image. Heres the code from the user guide.

    Code:
    <actinic:block if="%3cactinic%3avariable%20name%3d%22IsPopUpDisplayedByImage%22%20%2f%3e">
       <actinic:block if="%3cactinic%3avariable%20name%3d%22ExtendedInformationType%22%20%2f%3e%20%3d%3d%20%22Opens%20in%20a%20Pop%2dUp%20Window%22">
          <a href="javascript:ShowPopUp('<actinic:variable name=ExtendedInfoPageEncoded />',<actinic:variable name="ExtInfoWindowWidth" />,<actinic:variable name="ExtInfoWindowHeight" />);">
       </actinic:block>
       <actinic:block if="%3cactinic%3avariable%20name%3d%22ExtendedInformationType%22%20%2f%3e%20%3d%3d%20%22Opens%20in%20the%20Same%20Window%22" >
          <a href="<actinic:variable name="ExtendedInfoPageName" />">
       </actinic:block>
    </actinic:block>
    
    <actinic:block if="%3cactinic%3avariable%20name%3d%22IsProductImageDisplayed%22%20%2f%3e">
          
    <actinic:block php="true" >
       // START Create a thumbnail image t_ProductImageFileName
     	$sOriginalImageName = '<actinic:variable  encoding="perl" name="ProductImageFileName"  selectable="false" />';
    	$sThumbImageName = 't_' . $sOriginalImageName;
    	$image = @imagecreatefromjpeg($sOriginalImageName); /* Attempt to open */
        	if (!$image) 
    			{ /* See if it failed */
    			echo "<br><font color=red>Thumbnail creation error opening: $sOriginalImageName </font>";
    			}
    		else
    			{
    			// Get new dimensions
    			$width = imagesx($image);
    			$height = imagesy($image);
    			$t_width = 100;
    			$t_height = $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 image creation failed: $sThumbImageName </font><br>";
    				}
    			else
    				{
    				echo "<br><img src=\"$sThumbImageName\" width=\"$t_width\" height=\"$t_height\" border=\"0\" />";
    				}	
    			}
     // END Create a thumbnail image t_ProductImageFileName
     </actinic:block>  
            
          
    </actinic:block>
    
    <actinic:block if="%3cactinic%3avariable%20name%3d%22IsProductImageDisplayed%22%20%2f%3e%20%3d%3d%20False">
       <img src="<actinic:variable name="DefaultProductImage" />"
          border="0"
          alt="<actinic:variable name="ProductName" />" />
    </actinic:block>
    
    <actinic:block if="%3cactinic%3avariable%20name%3d%22IsPopUpDisplayedByImage%22%20%2f%3e">
       </a>
    </actinic:block>
    When I try this I get the following error?

    Code:
    Warning: imagejpeg(): Unable to open 't_Medium_Images\Haglof-Rucksacks\medium_haglofs_matrix_charcoal_2.jpg' for writing in main on line 21 Thumbnail image creation failed: t_Medium_Images\Haglof-Rucksacks\medium_haglofs_matrix_charcoal_2.jpg
    Any suggestions?

    Thanks.

    #2
    I wrote that. There's a possibility that those backslashes are being interpreted as escape sequences. Try this

    Look for

    Code:
     	$sOriginalImageName = '<actinic:variable  encoding="perl" name="ProductImageFileName"  selectable="false" />';
    immediately after that add
    Code:
     	$sOriginalImageName = str_replace('\\', '/', $sOriginalImageName);	// replace troublesome backslashes;
    Let us know if that fixes things so the AUG can be updated.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Thanks Norman,

      Unfortunately that has not helped. I still get the same error message.

      Comment


        #4
        i think the problem is that your original images are in sub-folders.

        we had a similar problem using this, and found that to get round it we needed to store all our original images in a folder (images) and then have all the thumbs, small and large images created in sub-folders (images/thumbs, images/small and images/large).

        Code:
        $sOriginalImageName = ('<actinic:variable  encoding="perl" name="ProductImageFileName"  selectable="false" />');
         	$sNewImageName = ltrim($sOriginalImageName,'images/');
        	$sThumbImageName = stripslashes('images/thumbs/t_' . $sNewImageName);
        $sSmallImageName = stripslashes('images/small/s_' . $sNewImageName);
        	$sLargeImageName = stripslashes('images/large/l_' . $sNewImageName);
        	$image = @imagecreatefromjpeg($sOriginalImageName); /* Attempt to open */
        the above code removes the 'images/' path from the original filename and adds the path 'images/thumbs/' and the prefix 't_' to the new image before saving it.

        yours is currently adding 't_' at the beginning of the full path to the image.

        so if you move all your original images to one folder and modify the above you should be able to get this working...

        hope that helps.

        Comment


          #5
          Thanks Dallen, that helped.

          The problem was because of the sub-folders.

          I got round the problem by writing some more php code to ignore the sub-folders.

          So its all working nicely, however each time I click on a section/product in actinic, the page loads slower as it is creating the images and slowing actinic down.

          Is there a way of speeding it up?

          Comment


            #6
            BOOM! headshot!

            no, and the reason is that your pages are now processing php as well as all the normal stuff they process.

            Comment

            Working...
            X