i am storeing image in database type long blob.

//STORE IMAGE IN $IMAGE
    $image = chunk_split(base64_encode(file_get_contents($_FILES['fileupload']['tmp_name'])));

     //store image name in $image_full_name(.jpeg)
    $image_full_name = $_FILES['fileupload']['name'];

    //store image size in $image_size than conver to 100x100
    $image_width_height = getimagesize($_FILES['fileupload']['tmp_name']);
    $image_resolution = $image_width_height[0] . "X" . $image_width_height[1];  //size of image 100x100

    //get size in binary 
    $file_size = filesize($file); //get image size, than change to b, kd, mb, or gb

    //change image size to b,kb or mb
    if ($file_size < 1024) { $file_size = $filesize . " B"; }
    else if($file_size < 1048576)  { $file_size = round($file_size / 1024, 2) . " KB"; }
    else if($file_size < 1073741824) { $file_size = round($file_size / 1048576, 2) . ' MB'; } 
    else if ($file_size < 1099511627776) { $file_size = round($file_size / 1073741824, 2) . ' GB'; }

here if the $file_size is in mb or gb i want to cange the size into kb's.

if(strstr($file_size, 'M') || strstr($file_size,'G'))
{
   //image is too big so change it to KB's     
   //need help herererererererererererereereerereererererer!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}

i was thinking some thing like this???
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg();
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
not sure what go in 2nd line

here is an image manipulator class I just wrote for this question. Save as image.class.php

<?php

## this image manipulator class was written by veedeoo or poorboy 2012
## feel free to modify, extend this clas as you wish.
## does not have any warranty of any kind

class ReduceImage{
    private $imageLoc = null;
    private $outImageLoc = null;
    private $imageResizePoint = null;


    public function __construct($imageLoc,$outImageLoc,$imageQuality){
        $this->imgLoc = $imageLoc;
        $this->outLoc = $outImageLoc;
        $this->quality = $imageQuality;
    }

    protected function getImageInfo(){
     list($this->x,$this->y) = getimagesize($this->imgLoc);

     return array($this->x, $this->y);

    }
    public function createImage(){
        $this->imageX_Y = self::getImageInfo();
        $this->newImage = imagecreatetruecolor($this->imageX_Y[0],$this->imageX_Y[1]);

        ## in production server use code below
        //$this->newImage = @imagecreatetruecolor($imageX_Y[0],$imageX_Y[1])

      //$this->newX_Y = self::getImageInfo();
      $this->newfile = imagecreatefromjpeg($this->imgLoc);
      imagecopyresampled($this->newImage, $this->newfile, 0, 0, 0, 0, $this->imageX_Y[0], $this->imageX_Y[1], $this->imageX_Y[0], $this->imageX_Y[1]);


     imagejpeg($this->newImage,$this->outLoc,$this->quality);
     ## in production server use code below
     //@imagejpeg($this->newImage,$this->outLoc,$this->quality);

     return $this->outLoc;
     imagedestroy($this->newImage);
     imagedestroy($this->newfile);

    }





}

?>

Sample usage of the class above..You should not have any problem implementing this to your script above.. I don't write full codes for advance users..

<?php

include_once 'image.class.php';

## define quality..quality value range from 10 to 100 10 or worst to highest quality.

$quality = 50;
$inputImage = "someImage.jpg";
$outputImage = "output.jpg";

## instantiate the class
$reducethis = new ReduceImage($inputImage , $outputImage , $quality);

## create the new image with smaller size
$image = $reducethis->createImage();

## display reduced image
echo '<img src="'.$image.'">';


?>

That's it .... good luck.. reference? read more here.

UPDATE! class above has been updated: I removed the possible reduncy of calling another instance of createImage ().

thanks alot i tierd it and it works.

do you know if there a way to do this without using function and classes?

you mean procedural coding style? Sure why not.. that's even a lot easier, but cannot be reuse unlike the OOP style.

Here we go..

<?php
## image reducer in procedural coding style.. by veedeoo or poorboy 2012
## define your image input, output and quality.
## provide data as array('inputImage','outPutImage', quality)
## quality range are 10 to 100 ..

$imageInfo = array('images/sample.jpg','images/output.jpg', 30);

################# NO EDIT ZONE BEGINS ##############################

## get the width x, and the height y. 
list($x,$y) = getimagesize($imageInfo[0]);  

## create a blank canvas where the new resized image is going to be layered.
$canvas = imagecreatetruecolor($x, $y);

## use code below in production server.
//$canvas = @imagecreatetruecolor($x, $y);

## prepare and create the new reduce image using the source file
$preparedImage = imagecreatefromjpeg($imageInfo[0]);

## generate the new reduced image.
## actually, this process will draw the reduce image on top of the canvas
imagecopyresampled($canvas, $preparedImage, 0, 0, 0, 0, $x, $y, $x, $y);

## lastly save the new image
imagejpeg($canvas, $imageInfo[1], $imageInfo[2]);

## free up some menory
imagedestroy($canvas); 
imagedestroy($preparedImage);

################## END OF NO EDIT ZONE #############################


## print image on the screen

echo '<img src="'.$imageInfo[1].'" />';

?>

There you have it. I still preferred the one written in OOP, because it can be extended to grab image from a remote url if needed...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.