Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Junior Member BurgerBoy's Avatar
    Join Date
    Jun 2003
    Location
    New Zealand
    Posts
    8
    Member #
    1650
    Hi people. I'm having trouble with using php to resize images for me. Or even show the image for that matter.

    Here is the code I use on the image_resize.php page:

    PHP Code:
    <?

    if (!$max_width)
        
    $max_width 150;
    if (!
    max_height)
        
    $max_height 100;

    $size GetImageSize($image);
    $width $size[0];
    $height $size[1];

    $x_ratio $max_width $width;
    $y_ratio $max_height $height;

    if ( (
    $width <= $max_width) && ($height <= $max_height) ) {
        
    $tn_width $width;
        
    $tn_height $height;
    }
    else if ((
    $x_ratio $height) < $max_height) {
        
    $tn_height ceil($x_ratio $height);
        
    $tn_width $max_width;
    }
    else {
        
    $tn_width ceil($y_ratio $width);
        
    $tn_height $max_height;
    }

    $src ImageCreateFromJpeg($image);
    $dst ImageCreate($tn_width,$tn_height);
    ImageCopyResized($dst$src0000,
    $tn_width,$tn_height,$width,$height);
    header(“Content-typeimage/jpeg”);
    ImageJpeg($dstnull, -1);
    ImageDestroy($src);
    ImageDestroy($dst);

    ?>
    Now, This is called on another page via the image url which is taken from a database:

    PHP Code:
    <img src="../images/serv_images/image_resize.php?image=<?php echo $row_rsService['service_img']; ?>">
    The folder 'images/serv_images' is where the images are located.

    Should the image_resize page be in that folder?

    But the biggest problem is that the images aren't displaying. Anyone know why?

    Thanks in advance. :classic:

  2.  

  3. #2
    Junior Member BurgerBoy's Avatar
    Join Date
    Jun 2003
    Location
    New Zealand
    Posts
    8
    Member #
    1650
    anyone?? I really need some help with this.

  4. #3
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    Try putting this on top of your image_resize script:
    PHP Code:
     $image 'images/serv_images/'.$image
    There and Back Again :Ogre:

  5. #4
    Junior Member BurgerBoy's Avatar
    Join Date
    Jun 2003
    Location
    New Zealand
    Posts
    8
    Member #
    1650
    It still doesn't work

    I think it has something to do with this code here, but am not sure.

    PHP Code:
    $src ImageCreateFromJpeg($image);
    $dst ImageCreate($tn_width,$tn_height);
    ImageCopyResized($dst$src0000,
    $tn_width,$tn_height,$width,$height);
    header(“Content-typeimage/jpeg”);
    ImageJpeg($dstnull, -1);
    ImageDestroy($src);
    ImageDestroy($dst); 

  6. #5
    Member Seraph's Avatar
    Join Date
    Sep 2003
    Posts
    81
    Member #
    3090
    Do you have the GD extension for php installed? If it is not then it will not work.

  7. #6
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    "The image isn't showing..."

    Do you mean you get no output whatsoever, or do you get a lot of garbled machinecode where your image's supposed to be?

    If the first, then something's wrong with your code. PHP.net has lots of working examples of how to resize images.

    If the latter, then you need to write your resized image to a file before calling it through the HTML "<img src=""> tag. By sending the "header(“Content-type: image/jpeg”);", you're effectively converting the whole page to an imagedisplay. The page cannot contain any other HTML-tags. If the page's supposed to contain any other information, you have to use the <img src..-tag referring to a static image (which of course may have been recently created through PHP code)


    I'm far from an authority on GD functions, but I picked up the above from the PHP-BIBLE (Tim Converse, Joyce Park)
    S. Rosland

  8. #7
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    I found that if you try to resize an image to s size larger than the original, i get all black or nothing at all. Make sure that the ending size is smaller than the start.
    ie:

    $new_width = ($old_width < $new_width) ? $old_width : $new_width;

    And also for height. This will set the new width to the old width if the old width is smaller than the new.
    If its not in Family Guy its not worth it.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:27 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com