Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-29-2012, 08:27 AM   PM User | #1
kamkam
Regular Coder

 
Join Date: Dec 2006
Posts: 306
Thanks: 24
Thanked 0 Times in 0 Posts
kamkam is an unknown quantity at this point
could not output resize image

Hi;

I got a problem to output resize image after i check the type of image.
Could anyone help me, thanks.

The test_1.php has not problem to output image, but the test_2.php could not output image.

test_1.php

PHP Code:
<?php
$image
=$_GET['image'];
// The file
$filename '../images/thread_images/'$image;

// Set a maximum height and width
$width 200;
$height 200;

// Content type
header('Content-Type: image/jpeg');


// Get new dimensions
list($width_orig$height_orig) = getimagesize($filename);

$ratio_orig $width_orig/$height_orig;

if (
$width/$height $ratio_orig) {
   
$width $height*$ratio_orig;
} else {
   
$height $width/$ratio_orig;
}

// Resample
$image_p imagecreatetruecolor($width$height);
$image imagecreatefromjpeg($filename);
imagecopyresampled($image_p$image0000$width$height$width_orig$height_orig);

// Output
imagejpeg($image_pnull100);


?>

test_2.php

PHP Code:
<?php
$image
=$_GET['image'];
// The file
$filename '../images/thread_images/'$image;

// Set a maximum height and width
$width 200;
$height 200;

// Content type

if(exif_imagetype($filename)==IMAGETYPE_JPEG)
  
header('Content-Type: image/jpeg');
else if(
exif_imagetype($filename)==IMAGETYPE_GIF)
  
header('Content-Type:image/gif'); 


// Get new dimensions
list($width_orig$height_orig) = getimagesize($filename);

$ratio_orig $width_orig/$height_orig;

if (
$width/$height $ratio_orig) {
   
$width $height*$ratio_orig;
} else {
   
$height $width/$ratio_orig;
}

// Resample
$image_p imagecreatetruecolor($width$height);
$image imagecreatefromjpeg($filename);
imagecopyresampled($image_p$image0000$width$height$width_orig$height_orig);

// Output


  
if(exif_imagetype($filename)==IMAGETYPE_JPEG)
    
imagejpeg($image_pnull100);
  else if(
exif_imagetype($filename)==IMAGETYPE_GIF)
     
imagegif($image_pnull100); 

?>

Last edited by kamkam; 02-29-2012 at 09:11 AM..
kamkam is offline   Reply With Quote
Old 02-29-2012, 01:50 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,648
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Check your error logs; does it show any problems with the calls to exif functions? Make sure you are testing with a jpg as well, this won't work with gif.
Fou-Lu is offline   Reply With Quote
Old 02-29-2012, 09:00 PM   PM User | #3
kamkam
Regular Coder

 
Join Date: Dec 2006
Posts: 306
Thanks: 24
Thanked 0 Times in 0 Posts
kamkam is an unknown quantity at this point
i put the "http://www.xxxx.com/account/display_thread_image.php?thread_photo_91Winter Leaves.jpg" into browser, and i have the warning;
Fatal error: Call to undefined function exif_imagetype()


but it is builded in fuction?
kamkam is offline   Reply With Quote
Old 02-29-2012, 10:24 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,648
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Not exactly; exif is an external package provided with the original source code. Its available, but has to be enabled.
You need to contact your host in order to enable the exif functionality, or if its your own machine you can configure php on linux adding the --enable-exif, or by configuring PHP.ini in windows to allow php_mbstring.dll and php_exif.dll. The installation doc does indicate that mbstring MUST be available before exif, so it has to be moved up in the ini file.

getimagesize returns its guestimate of the file based on extension under the third offset. Will use the same constants you have here. An alternative is to open the file and scan in the header to determine the filetype, but that takes some knowledge of filestructures and how to implement them in PHP. Types are usually easy as they are represented by clear text (JFIF for example), but some are more complicated in how the are presented (png I think is right at the start of the file, but jpeg's I think are further in).
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
kamkam (03-01-2012)
Old 03-01-2012, 02:40 AM   PM User | #5
kamkam
Regular Coder

 
Join Date: Dec 2006
Posts: 306
Thanks: 24
Thanked 0 Times in 0 Posts
kamkam is an unknown quantity at this point
Thanks a lot, the host have enable the fuction for me already.
kamkam is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:37 PM.


Advertisement
Log in to turn off these ads.