Current location: Hot Scripts Forums » Programming Languages » PHP » Script Help Needed...


Script Help Needed...

Reply
  #1 (permalink)  
Old 07-01-05, 11:09 AM
Brian07002 Brian07002 is offline
New Member
 
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Script Help Needed...

Hi all,

Can someone please help me connect the bottom script with the top script? The results should be that each image that is randomly displayed will be resized proportionaly.

Code:
<?
// This is the random product script

// Connect to the database
mysql_connect ('host', 'user', 'pass') ;
mysql_select_db ('dbname'); 

// Edit this number to however many links you want displaying
$num_displayed = 1 ;

// Select random rows from the database
$result = mysql_query ("SELECT * FROM products ORDER BY RAND() LIMIT $num_displayed"); 

// For all the rows that you selected
while ($row = mysql_fetch_array($result)) 

{
// Display them to the screen...

echo "<a href=\"http://www.brothersvarietystore.com/shop/index.php?p=product&id=" . $row["pid"] ."&parent=" . $row["cid"] . "\">
<img src=\"" . $row["image_url"] . "\" border=1 alt=\"" . $row["title"] . "\">
</a>" ;
}
?>

Code:
// The script below is a GD image sizing script (by proportions) that I am trying to use in conjunction with the script above.

<?php
/*
You call it like so:
resizeImage ($src, $dest, $newHeight, $newWidth)

$src = . 
$dest = 
$newHeight = 
$newWeight = 
*/
  function resizeImage ($src, $dest, $newHeight, $newWidth)
  {
    if ( $dest )
    {
      fopen($dest, "w") ||
        die("Can not write to $dest.  Check directory permissions!");
    }
    $imgInfo = getimagesize($src); $width = $imgInfo[0]; $height = $imgInfo[1];
    $file_type = $imgInfo[2];
    if ( $newHeight || $newWidth )
    {
      if ( $newHeight && $newWidth )
      {
        $width = $newWidth;
        $height = $newHeight;
      } else {
        if ( $newWidth == "0" )
        {
          $ratio = (intval(($width / $newWidth) * 100)) / 100;
          $width = (intval(($width / $ratio) * 100)) / 100;
          $height = (intval(($height / $ratio) * 100)) / 100;
        } else {
          $ratio = (intval(($width / $newHeight) * 100)) / 100;
          $width = (intval(($width / $ratio) * 100)) / 100;
          $height = (intval(($height / $ratio) * 100)) / 100;
        }
      }
    }
    $destimg=ImageCreateTrueColor($width,$height);
    switch ($file_type)
    {
      case 1:
        $srcimg = imagecreatefromgif($src);
        if (function_exists(ImageGIF))
        {
          $imgType = "gif";
        } else {
          $imgType = "jpeg";
        }
        break;
      case 2:
        $srcimg = imagecreatefromjpeg($src);
        $imgType = "jpeg";  
        break;
      case 3:
        $srcimg = imagecreatefrompng($src);
        $imgType = "png";
        break;
      default:
        break;
    }
    ImageCopyResized($destimg,$srcimg,0,0,0,0,$width,$height,ImageSX($srcimg),ImageSY($srcimg));
    if ( !$dest ) { header ("Content-type: image/$imgType"); }
    switch ($file_type)
    {
      case 1:
        if (function_exists(ImageGIF))
        {
          if ( $dest) { imagegif ($destimg, $dest); } else { imagegif($destimg); }
        } else {
          if ( $dest) { imagejpeg ($destimg, $dest); } else { imagejpeg($destimg); }
        }
        break;
      case 2:
        if ( $dest) { imagejpeg ($destimg, $dest); } else { imagejpeg($destimg); }
        break;
      case 3:
        if ( $dest) { imagepng ($destimg, $dest); } else { imagepng($destimg); }
        break;
      default:
        break;
    }
    imagedestroy ($srcimg);
    imagedestroy ($destimg);
  }
?>
Thank you!
-Brian
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
custom php script needed alley Job Offers & Assistance 5 06-30-10 03:14 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 11:17 AM
eBay / PayPal auction payment script needed Synthetic Job Offers & Assistance 3 03-06-06 12:40 PM
Artist pages script needed SR_Ben Script Requests 0 07-09-04 03:30 PM
will pay. php script needed. upload, resize, & email jamjammo Script Requests 4 02-29-04 09:30 PM


All times are GMT -5. The time now is 08:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.