Jump to content

[SOLVED] Image Jpeg function problems


Dan911

Recommended Posts

I am having some problems using the imagejpeg() function. The script i am wrote successfully saved a resized image, but displays a white page with the url that loads without the inclusion of the imagejped code. 

(instead of resizing the image and loading the page mysite.com, it resizes the image and displays a white page with the url mysite.com written in the upper left hand corner)

Is this function trying to create its own new page, and how can i get it to load the page instead of displaying the url, as the php file does without the inclusion of the imagejpeg code?

 

//if statement beings that does the imageressize
if ($root_name == 'temp')
        {
          $image = open_image($_SERVER['DOCUMENT_ROOT'].'/'.$_POST['imageresize']);
          if ($image === false) { die ('Unable to open image' . $_SERVER['DOCUMENT_ROOT'].'/'.$_POST['imageresize']); }

          // Get original width and height
          $width = imagesx($image);
          $height = imagesy($image);


          // Set a new width, and calculate new height
          $new_width = 200;
          $new_height = $height * ($new_width/$width);

          // Resample
          $image_resized = imagecreatetruecolor($new_width, $new_height);
          imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

         
          header('Content-Type: image/jpeg');
	  
	 imagejpeg($image_resized,'../images/resizedimage.jpg');

       
        

          function open_image ($file)
          {
                   # JPEG:
                   $im = @imagecreatefromjpeg($file);
                   if ($im !== false) { return $im; }

                    # GIF:
                     $im = @imagecreatefromgif($file);
                     if ($im !== false) { return $im; }

                     # PNG:
                     $im = @imagecreatefrompng($file);
                     if ($im !== false) { return $im; }

                     # GD File:
                     $im = @imagecreatefromgd($file);
                     if ($im !== false) { return $im; }

                     # GD2 File:
                     $im = @imagecreatefromgd2($file);
                     if ($im !== false) { return $im; }

                     # WBMP:
                     $im = @imagecreatefromwbmp($file);
                     if ($im !== false) { return $im; }

                     # XBM:
                     $im = @imagecreatefromxbm($file);
                     if ($im !== false) { return $im; }

                     # XPM:
                     $im = @imagecreatefromxpm($file);
                     if ($im !== false) { return $im; }

                     # Try and load from string:
                     $im = @imagecreatefromstring(file_get_contents($file));
                     if ($im !== false) { return $im; }

                     return false;
           }
	}
// more code that does not relate to the function
[/code

Link to comment
https://forums.phpfreaks.com/topic/61377-solved-image-jpeg-function-problems/
Share on other sites

Archived

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

×
×
  • 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.