Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts

    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    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?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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).

  • Users who have thanked Fou-Lu for this post:

    kamkam (03-01-2012)

  • #5
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Thanks a lot, the host have enable the fuction for me already.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •