resizing an image.

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

    #1

    resizing an image.



    Hi group,

    What is the best way to rersize an image to a specific width and
    height?

    Any samples?


    Thanks.
  • amit

    #2
    Re: resizing an image.

    On Apr 1, 4:02 pm, amit <amit.ko...@gma il.comwrote:
    Hi group,
    >
    What is the best way to rersize an image to a specific width and
    height?
    >
    Any samples?
    >
    Thanks.

    Just to explain my case:

    Currently I have a png file. it will be uploaded and then converted to
    JPEG file. Either before conversion or after conversion (which is
    better?) I need to change the size of it to be width=320 pixcel and
    height =240 pixcel


    Thanks.

    Comment

    • amit

      #3
      Re: resizing an image.

      On Apr 1, 4:19 pm, amit <amit.ko...@gma il.comwrote:
      On Apr 1, 4:02 pm, amit <amit.ko...@gma il.comwrote:
      >
      Hi group,
      >
      What is the best way to rersize an image to a specific width and
      height?
      >
      Any samples?
      >
      Thanks.
      >
      Just to explain my case:
      >
      Currently I have a png file. it will be uploaded and then converted to
      JPEG file. Either before conversion or after conversion (which is
      better?) I need to change the size of it to be width=320 pixcel and
      height =240 pixcel
      >
      Thanks.
      This is currently what I'm doing:


      $tmp = imagecreatetrue color($new_widt h, $new_height);
      imagecopyresamp led($dst, $file, 0,0,0,0, $new_width, $new_height, 320,
      240);

      imagejpeg($tmp, "/var/www/html/apps/sa/usr_bg_imgs/" . "newfile.pn g",
      100);


      However, generated image is a black image only!

      Comment

      • Krustov

        #4
        Re: resizing an image.

        <comp.lang.ph p>
        <amit>
        <Tue, 1 Apr 2008 16:02:53 -0700 (PDT)>
        <57d37985-0849-4530-8d59-9c51ba5f6f16@s8 g2000prg.google groups.com>
        What is the best way to rersize an image to a specific width and
        height?
        >
        Any samples?
        >
        The code below doesnt mind if the source image is widescreen or portrait
        as it will resize either to suit .



        $max_width=150;
        $max_height=107 ;

        $source="demo/blah.jpg";
        $thumb=imagecre atetruecolor($m ax_width,$max_h eight);
        $grab=imagecrea tefromjpeg($sou rce);

        $dummy="#FAF9EC "; include('colour _convert.php'); $kol=imagecolor allocate
        ($thumb,$grab1, $grab2,$grab3);
        imagefilledrect angle($thumb,0, 0,$max_width,$m ax_height,$kol) ;

        $size=GetImageS ize($source);
        $width_ratio=($ size[0]/$max_width);
        $height_ratio=( $size[1]/$max_height);

        if ($width_ratio>= $height_ratio)
        {$ratio=$width_ ratio;}
        else
        {$ratio=$height _ratio;}

        $new_width=($si ze[0]/$ratio);
        $new_height=($s ize[1]/$ratio);

        $glasgow=0; if ($new_width<$ma x_width) {$glasgow=75-$new_width/2;}

        $paisley=0; if ($new_height<$m ax_height) {$paisley=54-$new_height/2;}

        imagecopyresamp led($thumb,$gra b,$glasgow,$pai sley,0,0,$new_w idth,
        $new_height,$si ze[0],$size[1]);



        colour_convert. php being the following .....

        <?php

        $temp=str_repla ce("#","",$dumm y); $temp=strtouppe r($temp);

        $temp1=substr($ temp,0,2);
        $temp2=substr($ temp,2,2);
        $temp3=substr($ temp,4,2);

        $grab1=hexdec($ temp1);
        $grab2=hexdec($ temp2);
        $grab3=hexdec($ temp3);

        ?>


        Hardly stunning code - but it works fine and i've more important things
        to do than tinker around rewiting it .


        --

        Comment

        • Krustov

          #5
          Re: resizing an image.

          <comp.lang.ph p>
          <Krustov>
          <Wed, 2 Apr 2008 00:57:40 +0100>
          <MPG.225cd6b619 7effbb98b366@ne ws.newsreader.c om>
          imagecopyresamp led($thumb,$gra b,$glasgow,$pai sley,0,0,$new_w idth,
          $new_height,$si ze[0],$size[1]);
          >
          $jenny="poop/whatever.jpg";

          imagejpeg($thum b,$jenny,70); imagedestroy($t humb); imagedestroy($g rab);



          Add the above code that i snipped by mistake .

          Comment

          • amit

            #6
            Re: resizing an image.

            On Apr 1, 5:04 pm, Krustov <m...@privacy.n etwrote:
            <comp.lang.ph p>
            <Krustov>
            <Wed, 2 Apr 2008 00:57:40 +0100>
            <MPG.225cd6b619 7effbb98b...@ne ws.newsreader.c om>
            >
            imagecopyresamp led($thumb,$gra b,$glasgow,$pai sley,0,0,$new_w idth,
            $new_height,$si ze[0],$size[1]);
            >
            $jenny="poop/whatever.jpg";
            >
            imagejpeg($thum b,$jenny,70); imagedestroy($t humb); imagedestroy($g rab);
            >
            Add the above code that i snipped by mistake .


            Thank you but it is so confusing the way it is written in terms of
            variable names. Also, I get so many division by zero.

            However, I will do something about it.

            Thanks for your time.

            Comment

            Working...