Professional Web Applications Themes

Problem resizing images - PHP Development

Dear all. I build a class wich can resiz images. Now I have the following problem. When I show the image on the webpage only 70 percent of the image is shown. The image is reduced according to the following code $picWidth = 300 $picHeight = 220 $this->temp_name = $_FILES['image']['tmp_name'] list($this->width, $this->height, $type, $attr) = getimagesize($this->temp_name); $tempImage = imagecreatefromjpeg($this->temp_name); $thumb = imagecreatetruecolor($picWidth, $picHeight); imagecopyresized($thumb, $tempImage, 0, 0, 0, 0, $picWidth, $picHeight, $this->width, $this->height); imagejpeg($thumb, $this->temp_name,100); $this->size = filesize($this->temp_name); $this->binary = addslashes(fread(fopen($this->temp_name, "rb"), $this->size)); $this->binary is placed in the database The image is shown on the web according to the following. ...

  1. #1

    Default Problem resizing images

    Dear all.



    I build a class wich can resiz images. Now I have the following problem.
    When I show the image on the webpage only 70 percent of the image is shown.

    The image is reduced according to the following code



    $picWidth = 300

    $picHeight = 220



    $this->temp_name = $_FILES['image']['tmp_name']



    list($this->width, $this->height, $type, $attr) =
    getimagesize($this->temp_name);

    $tempImage = imagecreatefromjpeg($this->temp_name);

    $thumb = imagecreatetruecolor($picWidth, $picHeight);

    imagecopyresized($thumb, $tempImage, 0, 0, 0, 0, $picWidth, $picHeight,
    $this->width, $this->height);

    imagejpeg($thumb, $this->temp_name,100);

    $this->size = filesize($this->temp_name);

    $this->binary = addslashes(fread(fopen($this->temp_name, "rb"),
    $this->size));



    $this->binary is placed in the database



    The image is shown on the web according to the following.

    This is the php-file showimage.php

    session_start();

    header("Content type: image/jpg");

    echo ($_SESSION['image']);

    $_SESSION['image'] = '';



    Showimage.php is called upon as follows:

    <img src="showimage.php">



    The session $_SESSION['image'] is allready defined containing the image from
    the database

    The images are BLOB's



    The next awkward thing is also happening. It is not misbehaving with all
    jpg-image. I tested with one wich performed well. (I saw the whole image)
    and several wich went wrong. The only difference between those what I could
    determine was that the one which performed well was, when opened in
    Photoshop, RGB 8# and the ones wich did not perform well where, when opened
    in Photoshop, RGB/8.

    Someone one any idea what goes wrong here?



    Kind Regards

    Richard Wolterink





    Mvrgrt Richard Wolterink


    Richard Wolterink Guest

  2. #2

    Default Re: Problem resizing images


    "Richard Wolterink" <richard at deletethis thewebmen deletethisalso.com>
    wrote in message news:10gs6h13iit7f1fcorp.supernews.com...
    > Dear all.
    > I build a class wich can resiz images. Now I have the following problem.
    > When I show the image on the webpage only 70 percent of the image is
    shown.

    Richard,

    First I would tend to generate the image size from the image itself using
    getimagesize(). This prevents the new image being based on more or less than
    the original image.

    Your code will only work in the image is EXACTLY 220px x 300px

    Secondly, keeping images in a BLOB isn't very economical on processing power
    (or file space) as the database engine has to recover the image before the
    deserver can process it. better to keep the images as jpegs ( or png / gif
    etc) keeping the image name in the database.

    It should be possible to arrange for the images directory to be outside of
    the normal webserver scope, but still accessible via the server filesystem.
    this prevents web browsers from 'finding' them which I why I suspect the
    images were placed in the DB .

    Finally, there are some 'enhanced' forms of Jpeg which I don't fully
    understand - they have enhanced areas for better detail and imbedded
    thumbnails etc Exif I think they are called. From my experience, The GD /
    GD2 library doesn't cope well with these features. that could also be why
    you get partial images.

    HTH

    Ron


    jhgjhgu Guest

  3. #3

    Default Re: Problem resizing images

    Ron,

    Thanx for your advice.

    Instead of placing the images in blobs in the database I place the Images in
    directories and store the imagenames in the database.

    Problems are solved. Strange. I am using the same class for resizing the
    images. Something must have been wrong in the Interaction with the database.

    Kind regards,

    Richard Wolterink

    "jhgjhgu" <nbnbbmnhbjhbjh.con> wrote in message
    news:nOnQc.192$Ce1.96newsfe5-gui.ntli.net...
    >
    > "Richard Wolterink" <richard at deletethis thewebmen deletethisalso.com>
    > wrote in message news:10gs6h13iit7f1fcorp.supernews.com...
    > > Dear all.
    > > I build a class wich can resiz images. Now I have the following problem.
    > > When I show the image on the webpage only 70 percent of the image is
    > shown.
    >
    > Richard,
    >
    > First I would tend to generate the image size from the image itself using
    > getimagesize(). This prevents the new image being based on more or less
    than
    > the original image.
    >
    > Your code will only work in the image is EXACTLY 220px x 300px
    >
    > Secondly, keeping images in a BLOB isn't very economical on processing
    power
    > (or file space) as the database engine has to recover the image before the
    > deserver can process it. better to keep the images as jpegs ( or png / gif
    > etc) keeping the image name in the database.
    >
    > It should be possible to arrange for the images directory to be outside of
    > the normal webserver scope, but still accessible via the server
    filesystem.
    > this prevents web browsers from 'finding' them which I why I suspect the
    > images were placed in the DB .
    >
    > Finally, there are some 'enhanced' forms of Jpeg which I don't fully
    > understand - they have enhanced areas for better detail and imbedded
    > thumbnails etc Exif I think they are called. From my experience, The GD /
    > GD2 library doesn't cope well with these features. that could also be why
    > you get partial images.
    >
    > HTH
    >
    > Ron
    >
    >

    Richard Wolterink Guest

  4. #4

    Default Re: Problem resizing images

    Ron,

    Thanx for your advice.

    Instead of placing the images in blobs in the database I place the Images in
    directories and store the imagenames in the database.

    Problems are solved. Strange. I am using the same class for resizing the
    images. Something must have been wrong in the Interaction with the database.

    Kind regards,

    Richard Wolterink

    "jhgjhgu" <nbnbbmnhbjhbjh.con> wrote in message
    news:nOnQc.192$Ce1.96newsfe5-gui.ntli.net...
    >
    > "Richard Wolterink" <richard at deletethis thewebmen deletethisalso.com>
    > wrote in message news:10gs6h13iit7f1fcorp.supernews.com...
    > > Dear all.
    > > I build a class wich can resiz images. Now I have the following problem.
    > > When I show the image on the webpage only 70 percent of the image is
    > shown.
    >
    > Richard,
    >
    > First I would tend to generate the image size from the image itself using
    > getimagesize(). This prevents the new image being based on more or less
    than
    > the original image.
    >
    > Your code will only work in the image is EXACTLY 220px x 300px
    >
    > Secondly, keeping images in a BLOB isn't very economical on processing
    power
    > (or file space) as the database engine has to recover the image before the
    > deserver can process it. better to keep the images as jpegs ( or png / gif
    > etc) keeping the image name in the database.
    >
    > It should be possible to arrange for the images directory to be outside of
    > the normal webserver scope, but still accessible via the server
    filesystem.
    > this prevents web browsers from 'finding' them which I why I suspect the
    > images were placed in the DB .
    >
    > Finally, there are some 'enhanced' forms of Jpeg which I don't fully
    > understand - they have enhanced areas for better detail and imbedded
    > thumbnails etc Exif I think they are called. From my experience, The GD /
    > GD2 library doesn't cope well with these features. that could also be why
    > you get partial images.
    >
    > HTH
    >
    > Ron
    >
    >

    Richard Wolterink Guest

  5. #5

    Default Re: Problem resizing images

    "jhgjhgu" <nbnbbmnhbjhbjh.con> wrote in message
    news:nOnQc.192$Ce1.96newsfe5-gui.ntli.net...
    >
    > "Richard Wolterink" <richard at deletethis thewebmen deletethisalso.com>
    > wrote in message news:10gs6h13iit7f1fcorp.supernews.com...
    > > Dear all.
    > > I build a class wich can resiz images. Now I have the following problem.
    > > When I show the image on the webpage only 70 percent of the image is
    > shown.
    >
    > Richard,
    >
    > First I would tend to generate the image size from the image itself using
    > getimagesize(). This prevents the new image being based on more or less
    than
    > the original image.
    >
    > Your code will only work in the image is EXACTLY 220px x 300px
    >
    > Secondly, keeping images in a BLOB isn't very economical on processing
    power
    > (or file space) as the database engine has to recover the image before the
    > deserver can process it. better to keep the images as jpegs ( or png / gif
    > etc) keeping the image name in the database.
    >
    I have to disagree... at a certain point you will run into problems as
    your filesystem fills up with images. You'll either end up with thousands of
    images in one directory or you have to come up with an elaborate directory
    scheme to group the images into smaller directories. BLOBs are easy to work
    with once you get the hang of it (and there are some good tutorials out on
    the web).
    > It should be possible to arrange for the images directory to be outside of
    > the normal webserver scope, but still accessible via the server
    filesystem.
    > this prevents web browsers from 'finding' them which I why I suspect the
    > images were placed in the DB .
    >
    Placing an 'index.html' or 'index.php' file in the folder containing the
    images is a simple security measure. You can make it act like an error page:

    'You are not supposed to be here!'

    or even a redirect with the header function.
    >
    > Finally, there are some 'enhanced' forms of Jpeg which I don't fully
    > understand - they have enhanced areas for better detail and imbedded
    > thumbnails etc Exif I think they are called. From my experience, The GD /
    > GD2 library doesn't cope well with these features. that could also be why
    > you get partial images.
    >
    > HTH
    >
    > Ron
    >
    >
    To my knowledge i've not come across a jpeg GD2 didn't like...

    Norm


    --
    Avatar hosting at [url]www.easyavatar.com[/url]


    Norman Peelman Guest

Similar Threads

  1. Resizing Images Dynamically
    By Confused! in forum Macromedia ColdFusion
    Replies: 2
    Last Post: July 1st, 11:37 PM
  2. Resizing Placed Images
    By Paul_Welk@adobeforums.com in forum Adobe Indesign Windows
    Replies: 1
    Last Post: April 22nd, 07:11 PM
  3. i need some code for resizing images
    By lawrence in forum PHP Development
    Replies: 9
    Last Post: December 11th, 07:52 AM
  4. Resizing Images
    By Mac McDougald in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 16
    Last Post: October 15th, 11:06 PM
  5. resizing images using ASP component
    By Fredo Vincentis in forum ASP
    Replies: 2
    Last Post: July 4th, 07:06 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139