work with images

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

    work with images

    Hi,
    I wonder is there a way or a function to take a high resolution image
    and change it to low resolution ?? I have a directory with a 200
    pictures, and want to save them with the same width and height but with
    another lower resolution, can I do it automaticly with a script, not
    downloading them, changing them with image program and uploading them
    again..
    Thank you

  • Sandman

    #2
    Re: work with images

    In article <1134292976.906 952.307970@g14g 2000cwa.googleg roups.com>,
    "NurAzije" <nurazije@gmail .com> wrote:
    [color=blue]
    > Hi,
    > I wonder is there a way or a function to take a high resolution image
    > and change it to low resolution ?? I have a directory with a 200
    > pictures, and want to save them with the same width and height but with
    > another lower resolution, can I do it automaticly with a script, not
    > downloading them, changing them with image program and uploading them
    > again..[/color]

    You say you want to keep the width/height and change the resolution, which
    sounds like if you want to change the DPI. This will not alter the images size
    on disk at all. DPI is just a numerical value attached to an image that lets a
    printer know how big it should be on paper.

    As long as the pixels are the same, DPI doesn't change anything. I.e. a 200x200
    pixel large image in 72 dpi is the exact same size as a 200x200 pixel large
    image in 300 dpi.


    Generally, though, when you talk about high/low resolution images on the web,
    you are indeed talking about the image width/height in pixels. I.e. a very
    large image on the web makes for printing in a higher resolution than a smaller
    one.


    So, the question is, when you say "the same width and height", do you mean in
    pixels or a real world measurement (i.e. inches/centimeters)?

    Because, if you mean in inches (as in the image being 300x300 and it's in 300
    DPI and thus prints as a one-inch square on paper) you can calculate the new
    pixel ratio for each image to your new resolution.


    So:

    300x300 pixels @ 300 dpi = 1 inch^2
    150x150 pixels @ 150 dpi = 1 inch^2

    So, you have to lower the DPI along with the amount of pixels to keep the end
    result intact.

    PHP doesn't, as far as I know, have any tools to deal with DPI information in
    images. You might want to have a look at ImageMagick.


    --
    Sandman[.net]

    Edwin, on protecting against malware:
    "I use Avast AV, the Yahoo anti-spy toolbar, the MS anti-spy software,
    Windows SP2 with its firewall, AdAware, Spybot Search and Destroy, and
    SpywareBlaster. "

    Comment

    • NurAzije

      #3
      Re: work with images

      I ment the quality of images, I want them to be lighter for download,
      for example, some images are 2MB in JPG, by Adobe Photoshop or
      Fireworks or even Microsoft Imaging I can lower its size in MB to KB
      and change in it dimensions nothing.. Do understand me now, I have a
      website with images wich are too big for download..

      Comment

      • cover

        #4
        Re: work with images

        Screen captures with LviewPro works very well for this albeit, not an
        automatic process.

        On 11 Dec 2005 02:46:45 -0800, "NurAzije" <nurazije@gmail .com> wrote:
        [color=blue]
        >I ment the quality of images, I want them to be lighter for download,
        >for example, some images are 2MB in JPG, by Adobe Photoshop or
        >Fireworks or even Microsoft Imaging I can lower its size in MB to KB
        >and change in it dimensions nothing.. Do understand me now, I have a
        >website with images wich are too big for download..[/color]

        Comment

        • Alvaro G. Vicario

          #5
          Re: work with images

          *** NurAzije escribió/wrote (11 Dec 2005 02:46:45 -0800):[color=blue]
          > I ment the quality of images, I want them to be lighter for download,
          > for example, some images are 2MB in JPG, by Adobe Photoshop or
          > Fireworks or even Microsoft Imaging I can lower its size in MB to KB
          > and change in it dimensions nothing.. Do understand me now, I have a
          > website with images wich are too big for download..[/color]

          So you want to increase the JPEG compression ratio in order to get smaller
          files through decreasing picture quality.

          In the "Image Functions" chapter in PHP manual, imagejpeg() looks like what
          you're looking for. Read the whole index though, since there may be other
          useful functions.

          Also, there's a suite called ImageImagick with several command line tools
          for image processing. It's installed in most Linux servers and is a faster
          alternative to native PHP functions. You can use it via exec() or system().


          --
          -+ Álvaro G. Vicario - Burgos, Spain
          ++ http://bits.demogracia.com es mi sitio para programadores web
          +- http://www.demogracia.com es mi web de humor libre de cloro
          --

          Comment

          • VS

            #6
            Re: work with images

            NurAzije wrote:[color=blue]
            > I ment the quality of images, I want them to be lighter for download,
            > for example, some images are 2MB in JPG, by Adobe Photoshop or
            > Fireworks or even Microsoft Imaging I can lower its size in MB to KB
            > and change in it dimensions nothing.. Do understand me now, I have a
            > website with images wich are too big for download..[/color]

            Sounds to me like your images are just being re-sized by the application
            to fit the screen and all you really need to do is re-sample/re-scale
            them to reduce the on-disk size.

            I have a 10x6cm Photo which for test purposes I scanned at the highest
            resolution supported by my Photo Printer/Scanner this produced a 96MB
            (approx) Bitmap file which is 4279x6963 pixels. When converted to JPG
            this was reduced to 3MB on Disk. When this is loaded into a editor it is
            initially displayed at 1/10th scale (to fit on the screen) I can reduce
            the size to just 10% of the original (473x696) and it still displays at
            the same size on screen, but doing so reduces the file size to 51KB.

            --
            VS

            Comment

            • Mara Guida

              #7
              Re: work with images

              NurAzije wrote:[color=blue]
              > I wonder is there a way or a function to take a high resolution image
              > and change it to low resolution ??[/color]

              imagepjeg()
              Look it up on the manual: http://www.php.net/imagejpeg


              not tested
              <?php
              define('QUALITY ', '10'); // try different values here
              $filename = 'DSC09876.jpg';
              $im = imagecreatefrom jpeg($filename) ;
              imagejpeg($im, 'low_' . $filename, QUALITY);
              ?>

              Comment

              • John

                #8
                Re: work with images

                NurAzije wrote:[color=blue]
                > I ment the quality of images, I want them to be lighter for download,
                > for example, some images are 2MB in JPG, by Adobe Photoshop or
                > Fireworks or even Microsoft Imaging I can lower its size in MB to KB
                > and change in it dimensions nothing.. Do understand me now, I have a
                > website with images wich are too big for download..[/color]

                I know (and use) 2 ways:

                1) gimp - look into 'scripts fu', if you want to use that.

                2) php - I'll email you my script for doing it, let me know if
                you have any questions...

                It works on all images (between the set number range) with a filename
                of a given format - and OVERWRITES them !

                So I make large/medium/small directories of the original images,
                then run the script on the medium/small directories...

                It scales to a 'new major' side length, so the images can be portrait
                or landscape to start with.

                John.

                Comment

                • NurAzije

                  #9
                  Re: work with images

                  Thank you very much, I've done it, this is the script:
                  <?php
                  $ftp_server="Se rver";
                  $ftp_user_name= "UserName";
                  $ftp_user_pass= "Password";
                  $path="Director y_Path_of _Images";
                  $pathwww="FTP_D irectory_Path_o f_images";
                  $mode1="0777";
                  $mode2="0644";
                  $quality=70;
                  // set up basic connection
                  $conn_id = ftp_connect($ft p_server);
                  // login with username and password
                  $login_result = ftp_login($conn _id, $ftp_user_name, $ftp_user_pass) ;
                  //list the directory of images
                  $d = dir($path);
                  while(false !== ($e = $d->read())){
                  if(strpos($e,'. jpg')){
                  // try to chmod $file to 777
                  $file=$e;
                  $command1="CHMO D $mode1 $pathwww/$file";
                  $command2="CHMO D $mode2 $pathwww/$file";
                  @ftp_site($conn _id, $command1);
                  $r = imagecreatefrom jpeg($path."/".$e);
                  imagejpeg($r,st r_replace('.jpg ','.jpg',$e),$q uality);
                  @ftp_site($conn _id, $command2);
                  echo "Done $e<br>";
                  }
                  if(strpos($e,'. gif')){
                  // try to chmod $file to 777
                  $file=$e;
                  $command1="CHMO D $mode1 $pathwww/$file";
                  $command2="CHMO D $mode2 $pathwww/$file";
                  @ftp_site($conn _id, $command1);
                  $r = imagecreatefrom gif($path."/".$e);
                  imagegif($r,str _replace('.gif' ,'.gif',$e),$qu ality);
                  @ftp_site($conn _id, $command2);
                  echo "Done $e<br>";
                  }
                  if(strpos($e,'. png')){
                  // try to chmod $file to 777
                  $file=$e;
                  $command1="CHMO D $mode1 $pathwww/$file";
                  $command2="CHMO D $mode2 $pathwww/$file";
                  @ftp_site($conn _id, $command1);
                  $r = imagecreatefrom png($path."/".$e);
                  imagepng($r,str _replace('.png' ,'.png',$e),$qu ality);
                  @ftp_site($conn _id, $command2);
                  echo "Done $e<br>";
                  }
                  }
                  // close the connection
                  ftp_close($conn _id);
                  ?>

                  Comment

                  Working...