how to choose the correct height/width for images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kentor

    #1

    how to choose the correct height/width for images

    Hello,
    I have users that submit images to my website. By default I choose to
    make the width bigger than the height because usually pictures are
    taken horizontally... But in some cases people take pictures
    vertically so what I'm getting at is... can I know whether an image
    was taken horizontally or vertically so I can make the proper width/
    height lengths so that it looks nice and not kinda weird... because if
    you make the width bigger than the height of an image that is supposed
    to have a bigger height than width, it looks kinda ugly.. And also is
    there a way to know when I've enlarged the image too much? because if
    an image submitted was small and I make it bigger, then it also
    becomes kind of ugly to look at because I guess there aren't enough
    pixels... thanks for your help.

    Simon

  • Curtis

    #2
    Re: how to choose the correct height/width for images

    On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <kentor@gmail.c omwrote:
    Hello,
    I have users that submit images to my website. By default I choose to
    make the width bigger than the height because usually pictures are
    taken horizontally... But in some cases people take pictures
    vertically so what I'm getting at is... can I know whether an image
    was taken horizontally or vertically so I can make the proper width/
    height lengths so that it looks nice and not kinda weird... because if
    you make the width bigger than the height of an image that is supposed
    to have a bigger height than width, it looks kinda ugly.. And also is
    there a way to know when I've enlarged the image too much? because if
    an image submitted was small and I make it bigger, then it also
    becomes kind of ugly to look at because I guess there aren't enough
    pixels... thanks for your help.
    >
    Simon
    >
    If you are using the GD library, have a look at imagecopyresamp led:

    Example: "Example 2. Resampling an image proportionally"
    Copy and resize part of an image with resampling


    --
    Curtis, http://dyersweb.com

    Comment

    • Kentor

      #3
      Re: how to choose the correct height/width for images

      On Feb 1, 12:10 am, Curtis <dyers...@veriz on.netwrote:
      On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ken...@gmail.c omwrote:
      Hello,
      I have users that submit images to my website. By default I choose to
      make the width bigger than the height because usually pictures are
      taken horizontally... But in some cases people take pictures
      vertically so what I'm getting at is... can I know whether an image
      was taken horizontally or vertically so I can make the proper width/
      height lengths so that it looks nice and not kinda weird... because if
      you make the width bigger than the height of an image that is supposed
      to have a bigger height than width, it looks kinda ugly.. And also is
      there a way to know when I've enlarged the image too much? because if
      an image submitted was small and I make it bigger, then it also
      becomes kind of ugly to look at because I guess there aren't enough
      pixels... thanks for your help.
      >
      Simon
      >
      If you are using the GD library, have a look at imagecopyresamp led:
      >
      Example: "Example 2. Resampling an image proportionally" http://php.net/imagecopyresamp led
      >
      --
      Curtis,http://dyersweb.com
      Thanks, but this stuff will resize it to 200 by 200 as in the example
      or 50% of the original size... But I would like to have the image
      bigger horizontally if this is the images original setting... but I
      don't want the images original size because someone may upload a huge
      image that will take half the screen... so I need to figure out a way
      to know if the original image has a bigger width or height...

      Comment

      • CH4:D

        #4
        Re: how to choose the correct height/width for images

        Kentor wrote:
        On Feb 1, 12:10 am, Curtis <dyers...@veriz on.netwrote:
        On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ken...@gmail.c omwrote:
        Hello,
        I have users that submit images to my website. By default I
        choose to make the width bigger than the height because usually
        pictures are taken horizontally... But in some cases people take
        pictures vertically so what I'm getting at is... can I know
        whether an image was taken horizontally or vertically so I can
        make the proper width/ height lengths so that it looks nice and
        not kinda weird... because if you make the width bigger than the
        height of an image that is supposed to have a bigger height than
        width, it looks kinda ugly.. And also is there a way to know when
        I've enlarged the image too much? because if an image submitted
        was small and I make it bigger, then it also becomes kind of ugly
        to look at because I guess there aren't enough pixels... thanks
        for your help.
        Simon
        If you are using the GD library, have a look at imagecopyresamp led:

        Example: "Example 2. Resampling an image
        proportionally" http://php.net/imagecopyresamp led

        --
        Curtis,http://dyersweb.com
        >
        Thanks, but this stuff will resize it to 200 by 200 as in the example
        or 50% of the original size... But I would like to have the image
        bigger horizontally if this is the images original setting... but I
        don't want the images original size because someone may upload a huge
        image that will take half the screen... so I need to figure out a way
        to know if the original image has a bigger width or height...
        This may sound a little bit anti-user but it would be the only surefire
        way. You might want to add a note on the conditions to upload pictures.
        Like "please upload photos of height x width only". I don't think it
        can kill them to spruce up their images before they upload it. You can
        then add conditions in your code to trap images that don't match
        exactly what you're expecting and ditch it.

        Personally, I'd just resize all images to a reasonable size so it
        wouldn't look ugly regardless of orientation. You can do something like
        google images that wraps the images with a square box so that they all
        look all arranged in boxes to cancel out the random orientations.

        --

        Comment

        • Curtis

          #5
          Re: how to choose the correct height/width for images

          On Wed, 31 Jan 2007 21:15:25 -0800, Kentor <kentor@gmail.c omwrote:
          On Feb 1, 12:10 am, Curtis <dyers...@veriz on.netwrote:
          >On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ken...@gmail.c omwrote:
          Hello,
          I have users that submit images to my website. By default I choose to
          make the width bigger than the height because usually pictures are
          taken horizontally... But in some cases people take pictures
          vertically so what I'm getting at is... can I know whether an image
          was taken horizontally or vertically so I can make the proper width/
          height lengths so that it looks nice and not kinda weird... because if
          you make the width bigger than the height of an image that is supposed
          to have a bigger height than width, it looks kinda ugly.. And also is
          there a way to know when I've enlarged the image too much? because if
          an image submitted was small and I make it bigger, then it also
          becomes kind of ugly to look at because I guess there aren't enough
          pixels... thanks for your help.
          >>
          Simon
          >>
          >If you are using the GD library, have a look at imagecopyresamp led:
          >>
          >Example: "Example 2. Resampling an image
          >proportionally "http://php.net/imagecopyresamp led
          >>
          >--
          >Curtis,http://dyersweb.com
          >
          Thanks, but this stuff will resize it to 200 by 200 as in the example
          or 50% of the original size... But I would like to have the image
          bigger horizontally if this is the images original setting... but I
          don't want the images original size because someone may upload a huge
          image that will take half the screen... so I need to figure out a way
          to know if the original image has a bigger width or height...
          >
          That's the whole point, they specify arbitrary maximum size limits. If
          someone uploaded a huge image, it would be resampled to 200x200. You can
          change those size limits how you want. You can specify that the width is
          bigger than the height, if you want.

          --
          Curtis, http://dyersweb.com

          Comment

          • leader@congress.hotmail.com

            #6
            Re: how to choose the correct height/width for images

            On Thu, 01 Feb 2007 05:10:10 GMT, Curtis <dyersweb@veriz on.netwrote:
            >On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <kentor@gmail.c omwrote:
            >
            >Hello,
            >I have users that submit images to my website. By default I choose to
            >make the width bigger than the height because usually pictures are
            >taken horizontally... But in some cases people take pictures
            >vertically so what I'm getting at is... can I know whether an image
            >was taken horizontally or vertically so I can make the proper width/
            >height lengths so that it looks nice and not kinda weird... because if
            >you make the width bigger than the height of an image that is supposed
            >to have a bigger height than width, it looks kinda ugly.. And also is
            >there a way to know when I've enlarged the image too much? because if
            >an image submitted was small and I make it bigger, then it also
            >becomes kind of ugly to look at because I guess there aren't enough
            >pixels... thanks for your help.
            >>
            >Simon
            >>
            >
            >If you are using the GD library, have a look at imagecopyresamp led:
            >
            >Example: "Example 2. Resampling an image proportionally"
            >http://php.net/imagecopyresampled
            Also, the getimagesize function might provfe a helpful tool for some
            decision-making.

            Comment

            • lorento

              #7
              Re: how to choose the correct height/width for images

              You can use getimagesize() function. http://www.php.net/getimagesize

              You will get the height and width of the picture.
              If height width = portrait
              If width height = landscape

              Then you can resize the image e.g resize all height into 50 pixel
              newheight = 50
              newwidth = width * (50 / height)

              Or e.g resize image, if potrait height = 50, if landscape width = 50

              if portrait
              newheight = 50
              newwidth = width * (50 / height)

              if landscape
              newwidth = 50
              newheight = height * (50/width)

              ------



              On Feb 1, 12:42 pm, "CH4:D" <bill.ga...@mic rosoft.comwrote :
              Kentor wrote:
              On Feb 1, 12:10 am, Curtis <dyers...@veriz on.netwrote:
              On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ken...@gmail.c omwrote:
              Hello,
              I have users that submit images to my website. By default I
              choose to make the width bigger than the height because usually
              pictures are taken horizontally... But in some cases people take
              pictures vertically so what I'm getting at is... can I know
              whether an image was taken horizontally or vertically so I can
              make the proper width/ height lengths so that it looks nice and
              not kinda weird... because if you make the width bigger than the
              height of an image that is supposed to have a bigger height than
              width, it looks kinda ugly.. And also is there a way to know when
              I've enlarged the image too much? because if an image submitted
              was small and I make it bigger, then it also becomes kind of ugly
              to look at because I guess there aren't enough pixels... thanks
              for your help.
              >
              Simon
              >
              If you are using the GD library, have a look at imagecopyresamp led:
              >
              Example: "Example 2. Resampling an image
              proportionally" http://php.net/imagecopyresamp led
              >>
              Thanks, but this stuff will resize it to 200 by 200 as in the example
              or 50% of the original size... But I would like to have the image
              bigger horizontally if this is the images original setting... but I
              don't want the images original size because someone may upload a huge
              image that will take half the screen... so I need to figure out a way
              to know if the original image has a bigger width or height...
              >
              This may sound a little bit anti-user but it would be the only surefire
              way. You might want to add a note on the conditions to upload pictures.
              Like "please upload photos of height x width only". I don't think it
              can kill them to spruce up their images before they upload it. You can
              then add conditions in your code to trap images that don't match
              exactly what you're expecting and ditch it.
              >
              Personally, I'd just resize all images to a reasonable size so it
              wouldn't look ugly regardless of orientation. You can do something like
              google images that wraps the images with a square box so that they all
              look all arranged in boxes to cancel out the random orientations.
              >
              --

              Comment

              • Kentor

                #8
                Re: how to choose the correct height/width for images

                On Feb 1, 4:41 am, "lorento" <laurente1...@y ahoo.comwrote:
                You can use getimagesize() function.http://www.php.net/getimagesize
                >
                You will get the height and width of the picture.
                If height width = portrait
                If width height = landscape
                >
                Then you can resize the image e.g resize all height into 50 pixel
                newheight = 50
                newwidth = width * (50 / height)
                >
                Or e.g resize image, if potrait height = 50, if landscape width = 50
                >
                if portrait
                newheight = 50
                newwidth = width * (50 / height)
                >
                if landscape
                newwidth = 50
                newheight = height * (50/width)
                >
                ------http://www.mastervb.ne thttp://www.theaussiema p.comhttp://www.theukmap.co m
                On Feb 1, 12:42 pm, "CH4:D" <bill.ga...@mic rosoft.comwrote :
                >
                Kentor wrote:
                On Feb 1, 12:10 am, Curtis <dyers...@veriz on.netwrote:
                On Wed, 31 Jan 2007 20:58:57 -0800, Kentor <ken...@gmail.c omwrote:
                Hello,
                I have users that submit images to my website. By default I
                choose to make the width bigger than the height because usually
                pictures are taken horizontally... But in some cases people take
                pictures vertically so what I'm getting at is... can I know
                whether an image was taken horizontally or vertically so I can
                make the proper width/ height lengths so that it looks nice and
                not kinda weird... because if you make the width bigger than the
                height of an image that is supposed to have a bigger height than
                width, it looks kinda ugly.. And also is there a way to know when
                I've enlarged the image too much? because if an image submitted
                was small and I make it bigger, then it also becomes kind of ugly
                to look at because I guess there aren't enough pixels... thanks
                for your help.
                >
                Simon
                >
                If you are using the GD library, have a look at imagecopyresamp led:
                >
                Example: "Example 2. Resampling an image
                proportionally" http://php.net/imagecopyresamp led
                >>
                Thanks, but this stuff will resize it to 200 by 200 as in the example
                or 50% of the original size... But I would like to have the image
                bigger horizontally if this is the images original setting... but I
                don't want the images original size because someone may upload a huge
                image that will take half the screen... so I need to figure out a way
                to know if the original image has a bigger width or height...
                >
                This may sound a little bit anti-user but it would be the only surefire
                way. You might want to add a note on the conditions to upload pictures.
                Like "please upload photos of height x width only". I don't think it
                can kill them to spruce up their images before they upload it. You can
                then add conditions in your code to trap images that don't match
                exactly what you're expecting and ditch it.
                >
                Personally, I'd just resize all images to a reasonable size so it
                wouldn't look ugly regardless of orientation. You can do something like
                google images that wraps the images with a square box so that they all
                look all arranged in boxes to cancel out the random orientations.
                >
                --
                Aha! I think http://www.php.net/getimagesize will do the job, thanks :)

                Comment

                • VS

                  #9
                  Re: how to choose the correct height/width for images

                  Sounds like you need to re-size the image based on Width / Height Ratio
                  between the original image and your maximum desired size. I've not done
                  Image re-sizing in PHP, but you might be able to devise your own based
                  on this bit of Perl that I used:

                  # CreateThumbnail (Source, Destination)
                  sub CreateThumbnail
                  {
                  my( $src_file, $dst_file) = @_;

                  my $quality = 100;
                  my $newwidth = 160;
                  my $newheight = 120;

                  # create a new image from original
                  $im = GD::Image->newFromJpeg($s rc_file);
                  ($width, $height) = $im->getBounds();

                  # Width / Height Ratio's
                  $wr = $width / $newwidth;
                  $hr = $height / $newheight;

                  if ($wr $hr){
                  $newheight = int(($height / $wr)+0.5);
                  $newwidth = int(($width / $wr)+0.5);
                  }else{
                  $newheight = int(($height / $hr)+0.5);
                  $newwidth = int(($width / $hr)+0.5);
                  }

                  # new image for re-sized / re-sampled version
                  $outim = new GD::Image($neww idth, $newheight);
                  $outim->copyResized($i m, 0, 0, 0, 0, $newwidth, $newheight,
                  $width, $height);
                  $outim->interlaced('tr ue');

                  # Put a black frame around the Image
                  $black = $outim->colorAllocate( 0,0,0);
                  $outim->rectangle(0,0, $newwidth-1,$newheight-1,$black);

                  #save the new Image...
                  open(DST , '>', "$dst_file" ) || die "could not write image: $!";
                  binmode DST;
                  print DST ($outim->jpeg($quality) );
                  close(DST);
                  }

                  --
                  VS

                  Comment

                  Working...