Fixed Image Dimension WeBid 1.2.* ONLY

This fixes all image dimension by setting white space around image if needed without loosing quality

  1. BabyDunk
    WeBid Version:
    • 1.2.*
    if you would like all images uploaded to have the same dimension without loosing picture quality and scaled exact to the original image plus add a watermark then follow the steps below

    all editing will take place in sell.php in the WeBid root dir

    Under this
    PHP:
    $_SESSION['action'] = (!isset($_SESSION['action'])) ? $_SESSION['action'];
    $_SESSION['action'] = (!isset($_POST['action'])) ? $_SESSION['action'] : $_POST['action'];
    $ERR 'ERR_';
    $_SESSION['SELL_editing_category'] = false;
    $catscontrol = new MPTTcategories();

    Add this

    PHP:
    // Image Resizer and Watermark
    function resize($source_image$finished$tn_w$tn_h$quality 100$wmsource false)//if you wish to add a watermark replace ' $wmsource = false '  for the watermarks location ' $wmsource = "path_to_warkmark.png" '
    {
      
    $info getimagesize($source_image);
      
    $imgtype image_type_to_mime_type($info[2]);

      
    #assuming the mime type is correct
      
    switch ($imgtype) {
      case 
    'image/pjpeg':
      case 
    'image/jpeg':
      case 
    'image/jpg':
      
    $source imagecreatefromjpeg($source_image);
      break;
      case 
    'image/gif':
      
    $source imagecreatefromgif($source_image);
      break;
      case 
    'image/png':
      case 
    'image/x-png':
      
    $source imagecreatefrompng($source_image);
      break;
      default:
      die(
    'Invalid image type.');
      }

      
    #Figure out the dimensions of the image and the dimensions of the desired thumbnail
      
    $src_w imagesx($source);
      
    $src_h imagesy($source);


      
    #Do some math to figure out which way we'll need to crop the image
      #to get it proportional to the new size, then crop or adjust as needed

      
    $x_ratio $tn_w $src_w;
      
    $y_ratio $tn_h $src_h;

      if ((
    $src_w <= $tn_w) && ($src_h <= $tn_h)) {
      
    $new_w $src_w;
      
    $new_h $src_h;
      } elseif ((
    $x_ratio $src_h) < $tn_h) {
      
    $new_h ceil($x_ratio $src_h);
      
    $new_w $tn_w;
      } else {
      
    $new_w ceil($y_ratio $src_w);
      
    $new_h $tn_h;
      }

      
    $newpic imagecreatetruecolor(round($new_w), round($new_h));
      
    imagecopyresampled($newpic$source0000$new_w$new_h$src_w$src_h);
      
    $final imagecreatetruecolor($tn_w$tn_h);
      
    $backgroundColor imagecolorallocate($final255255255);
      
    imagefill($final00$backgroundColor);
      
    //imagecopyresampled($final, $newpic, 0, 0, ($x_mid - ($tn_w / 2)), ($y_mid - ($tn_h / 2)), $tn_w, $tn_h, $tn_w, $tn_h);
      
    imagecopy($final$newpic, (($tn_w $new_w)/ 2), (($tn_h $new_h) / 2), 00$new_w$new_h);

      
    #if we need to add a watermark
      
    if ($wmsource) {
      
    #find out what type of image the watermark is
      
    $info  getimagesize($wmsource);
      
    $imgtype image_type_to_mime_type($info[2]);

      
    #assuming the mime type is correct
      
    switch ($imgtype) {
      case 
    'image/pjpeg':
      case 
    'image/jpeg':
      case 
    'image/jpg':
      
    $watermark imagecreatefromjpeg($wmsource);
      break;
      case 
    'image/gif':
      
    $watermark imagecreatefromgif($wmsource);
      break;
      case 
    'image/png':
      case 
    'image/x-png':
      
    $watermark imagecreatefrompng($wmsource);
      break;
      default:
      die(
    'Invalid watermark type.');
      }

      
    #if we're adding a watermark, figure out the size of the watermark
      #and then place the watermark image on the bottom right of the image
      
    $wm_w imagesx($watermark);
      
    $wm_h imagesy($watermark);
      
    imagecopy($final$watermark$tn_w $wm_w$tn_h $wm_h00$tn_w$tn_h);

      }
      if (
    imagejpeg($final$finished$quality)) {

      
    imagedestroy($final);
      
    unlink($source_image);
      return 
    true;
      }
      return 
    false;
    }


    now look down the page for this

    PHP:
      // Copy files
      
    foreach ($UPLOADED_PICTURES as $k => $v)
      {
      
    $system->move_file(UPLOAD_PATH session_id() . '/' $vUPLOAD_PATH $auction_id '/' $v);
      
    chmod(UPLOAD_PATH $auction_id '/' $v0777);
      }


    Replace with this

    PHP:
      // Copy files
      
    foreach ($UPLOADED_PICTURES as $k => $v)
      {
      
    $source=(UPLOAD_PATH session_id() . '/' $v);
      
    $destination=(UPLOAD_PATH $auction_id '/' $v);
      
    resize($source$destination1024768);
      
    chmod(UPLOAD_PATH $auction_id '/' $v0777);
      }

    now on the function call, in this part you can change the image dimension . i have mine set to 1024px width by 768px height. You can change these numbers to suit your setup.

    now save file and go test and see if it works for you ;)

    ps: dont forget to change your fixed height rules in css

Recent Reviews

  1. sprokkel
    sprokkel
    4/5,
    Version: WeBid 1.2.* ONLY
    works good