Announcement

Collapse
No announcement yet.

multiple image resize question

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

    multiple image resize question

    I have used norman's script for image resizing found in the advanced users guide, though I want it to produce a number of different sized images for use across the site.
    I have created this though I would like to know if there is a more efficient way of doing this (shorter code, commented lines withstanding).

    I have also wrapped a few span tags with visibility and display set so that though the images are created they don't all display alongside each other (I want to use the original image for the enlarged image (therefore hidden) and the image set to width "250" as the main page image, evertything else being hidden). Again is there another way of doing the using block if statements?

    Here's the code:
    <span style="visibility:hidden; display:none">
    <actinic:block if="%3cactinic%3avariable%20name%3d%22IsProductImageDisplayed%22%20%2f%3e">
    <img src="<actinic:variable name="ProductImageFileName" />"
    id="im-<Actinic:Variable Name="EncodedProductAnchor" />"
    border="0"
    width="<actinic:variable name="ProductImageWidth" />"
    height="<actinic:variable name="ProductImageHeight" />"
    alt="<actinic:variable name="ProductName" />" />
    </actinic:block>
    </span>
    <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 = 250;
    $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 image creation failed: $sThumbImageName </font><br>";
    }
    else
    {
    echo "<img src=\"$sThumbImageName\" width=\"$t_width\" height=\"$t_height\" border=\"0\" alt=\"<actinic:variable name="ProductName" />\" title=\"<actinic:variable name="ProductName" />\" />";
    }
    }
    // END Create a thumbnail image t_ProductImageFileName
    </actinic:block>


    </actinic:block>

    <span style="visibility:hidden; display:none">
    <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" />';
    $sMicroImageName = 'm_' . $sOriginalImageName;
    $image = @imagecreatefromjpeg($sOriginalImageName); /* Attempt to open */
    if (!$image)
    { /* See if it failed */
    echo "<br><font color=red>Small creation error opening: $sOriginalImageName </font>";
    }
    else
    {
    // Get new dimensions
    $width = imagesx($image);
    $height = imagesy($image);
    $m_width = 55;
    $m_height = round($height * ($m_width / $width));

    // Resample
    $thumbimage = imagecreatetruecolor($m_width, $m_height);
    imagecopyresampled($thumbimage, $image, 0, 0, 0, 0, $m_width, $m_height, $width, $height);
    if ( ! imagejpeg($thumbimage, $sSmallImageName) )
    {
    echo "<font color=red>Thumbnail image creation failed: $sMicroImageName </font><br>";
    }
    else
    {
    echo "<img src=\"$sMicroImageName\" width=\"$m_width\" height=\"$m_height\" border=\"0\" alt=\"<actinic:variable name="ProductName" />\" title=\"<actinic:variable name="ProductName" />\" />";
    }
    }
    // END Create a thumbnail image m_ProductImageFileName
    </actinic:block>


    </actinic:block>
    </span>

    <span style="visibility:hidden; display:none">
    <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" />';
    $sSmlImageName = 's_' . $sOriginalImageName;
    $image = @imagecreatefromjpeg($sOriginalImageName); /* Attempt to open */
    if (!$image)
    { /* See if it failed */
    echo "<br><font color=red>Small creation error opening: $sOriginalImageName </font>";
    }
    else
    {
    // Get new dimensions
    $width = imagesx($image);
    $height = imagesy($image);
    $s_width = 155;
    $s_height = round($height * ($s_width / $width));

    // Resample
    $thumbimage = imagecreatetruecolor($s_width, $s_height);
    imagecopyresampled($thumbimage, $image, 0, 0, 0, 0, $s_width, $s_height, $width, $height);
    if ( ! imagejpeg($thumbimage, $sSmlImageName) )
    {
    echo "<font color=red>Thumbnail image creation failed: $sMicroImageName </font><br>";
    }
    else
    {
    echo "<img src=\"$sSmlImageName\" width=\"$s_width\" height=\"$s_height\" border=\"0\" alt=\"<actinic:variable name="ProductName" />\" title=\"<actinic:variable name="ProductName" />\" />";
    }
    }
    // END Create a thumbnail image m_ProductImageFileName
    </actinic:block>


    </actinic:block>
    </span>
    <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>
    Many thanks to whoever looks at this,
    regards
    bangers
    Boxhedge New Media Design
    Design and development solutions for SME's.
    Tel: 0118 966 2786
    Examples of work can be found at http://www.boxhedge.com
Working...
X