Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

resize image


vishalchauhan

Recommended Posts

hi,

 

is there any contribution in oscommerce for resize image and save(upload in directory)?

 

i want to resize image to small.... like if i have image size of 1200 X 800 it will resize to small like 300 X 200 and save it to images/small folder

 

Please help.

 

Thank you.

Please take backup of your files before do changes suggested by me

Link to comment
Share on other sites

ok friends

 

i have found a function for resize and upload image

 

i have put it to admin/includes/classes/uplaod.php

 

and call it when image upload function called up.

 

 

here is the function

 

<?php
function getExtension($str) {
$change="";
 $i = strrpos($str,".");
 if (!$i) { return ""; }
 $l = strlen($str) - $i;
 $ext = substr($str,$i+1,$l);
 return $ext;
}
function resize_upload_image($image_name,$image_temp_path,$small_image_path)
{
 $change="";

 $errors=0;

 $image =$image_name;//File name
 $uploadedfile = $image_temp_path;//Temp path of file

 if($image) 
 {
  $small_filename = stripslashes($image_name);
  $extension = $this->getExtension($small_filename);
  $extension = strtolower($extension);

  if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
  {
   $error .='Unknown Image extension \n';
   $errors=1;
  }
  else
  {   
   if($extension=="jpg" || $extension=="jpeg" )
   {
    $uploadedfile = $image_temp_path;
    $src = imagecreatefromjpeg($uploadedfile);     
   }
   else if($extension=="png")
   {
    $uploadedfile = $image_temp_path;
    $src = imagecreatefrompng($uploadedfile);     
   }
   else 
   {
    $src = imagecreatefromgif($uploadedfile);
   }
   echo $scr;

   list($width,$height)=getimagesize($uploadedfile);

   $newwidth1=150;
   $newheight1=150;

   if($height < $width){
    $newheight1=($height/$width)*$newwidth1;
   }else{
    $newwidth1=($width/$height)*$newheight1;
   }

   $tmp1=imagecreatetruecolor($newwidth1,$newheight1);

   imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);

   if($errors == 0){
    //Set path of image
    $filename1 = $small_image_path;
    //Upload image   
    imagejpeg($tmp1,$filename1,100); 
    imagedestroy($src);
    imagedestroy($tmp1);
    return true;
   }else{return false;}
  }
 }
}
?>

 

my question is.... when i upload gif image, it upload with chagned color like invert color of image or like nagetive image.

 

i have attached both file original image and uploaded image through function..

 

please check attachment..

 

anyone help..

 

Thanks in advance...

post-295170-0-15525000-1312784200_thumb.png

post-295170-0-61430900-1312784231_thumb.png

Please take backup of your files before do changes suggested by me

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...