Jump to content

Venom89

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Posts posted by Venom89

  1. Hey everyone.

     

    Having a little bit of trouble with using the php image functions and using images I have retrieved from my images database.

     

    Basically I am pulling out an image from the database and trying to resize it to fit my needs. Here is the signature of my function:

     

    function getImage($image_src, $imageType, $newWidth, $newHeight)

    Where $image_src is the image data itself.

     

    My problem is that most of the image functions files (e.g. imagecreatefromjpeg) require a filename as a parameter, not the image data itself. Is there any way around this?

     

    /**
    	@param $image_src The image data itself (pulled from blob in a database)
    	@param $image_type The type of the image (e.g. jpeg)
    	@param $newWidth The width we are aiming for
    	@param $newHeight The height we are aiming for
    */
    function getImage($image_src, $imageType, $newWidth, $newHeight)
    {
    
    	// Get the original geometry and calculate scales
       		list($width, $height) = getimagesize($img_src); // Won't work needs filename
        		$xscale=$width/$newWidth;
        		$yscale=$height/$newHeight;
        
        		// Recalculate new size with default ratio
        		if ($yscale>$xscale)
        		{
         		   $new_width = round($width * (1/$yscale));
          		   $new_height = round($height * (1/$yscale));
       		}
        		else 
        		{
            		$new_width = round($width * (1/$xscale));
            		$new_height = round($height * (1/$xscale));
        		}
        		
        		// Resize the original image
        		$imageResized = imagecreatetruecolor($new_width, $new_height);
        		if ($imageType == "image/jpeg")
        		{
        			$imageTmp     = imagecreatefromjpeg ($image_src);
        		}
        		else //if image is png etc.
        		{
        		}
        		
        		imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    
        		return $imageResized;
    
    }
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.