Image Resizer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Image Resizer

    i need an image resizer PHP script that resize images online
    check this script below, it works but only on jpg and jpeg image formats. i need 1 that will work on any image

    Code:
    <?php
    $height= 100;
    $width= 100;
    // Content type
    //You cant send more than one content type for image, so chose one
    //header(&#39;Content-type: image/jpeg&#39;);
    header(&#39;Content-type: image/jpg&#39;);
    //header(&#39;Content-type: image/gif&#39;);
    //header(&#39;Content-type: image/png&#39;);
    if(!$filename)
    $filename="./images/nopic.jpg";
    // Get new dimensions
    list($width_orig, $height_orig) = getimagesize($filename);
    
    if ($width && ($width_orig < $height_orig)) {
       $width = ($height / $height_orig) * $width_orig;
    } else {
       $height = ($width / $width_orig) * $height_orig;
    }
    
    // Resample
    $image_p = imagecreatetruecolor($width, $height);
    //$image = imagecreatefromjpeg($filename);
    //$image = imagecreatefromjpeg($filename);
    //$image = imagecreatefromjpeg($filename);
    $image = imagecreatefromjpeg($filename);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
    
    // Output
    //imagejpeg($image_p, null, 100);
    imagejpg($image_p, null, 100);
    //imagegif($image_p, null, 100);
    //imagePNG($image_p, null, 100);
    ImageDestroy ($image_p);
    ?>

    #2
    yu got cpanel or plesk, cos cpanel should have an image resizer
    Want something coded email me at sales@webnwaphost.com for a prices.




    Comment


      #3
      this script is on ngeo.ro @ gallery or avatar zone.


      Getting Started

      Let&#39;s say you have a great line of socks that you want to sell through your site. Well, you&#39;re proud of these fantastic socks and want people to see as much of them as possible: on the product views page, on the search page, on the listing page, etc. But this doesn&#39;t mean that you have to use the default image size each time, nor risk the quality of the image being degraded when it is stretched or crunched into a space. Some socks are longer than others and so you might have the image sizes ranging from 200x400 up to 600x750 pixels.

      To begin writing the function, we have to declare it as such... Then we have to throw in our attributes. We want to restrict our image, so we have to let the function know the dimensions to which we want to restrict it, and we have to know what the original image size is to begin with (we&#39;ll get to that part in a second).

      Code:
      <?php
      
      function imageResize($width, $height, $target) {
      
      //takes the larger size of the width and height and applies the  
      formula accordingly...this is so this script will work  
      dynamically with any size image
      
      if ($width > $height) {
      $percentage = ($target / $width);
      } else {
      $percentage = ($target / $height);
      }
      
      //gets the new value and applies the percentage, then rounds the value
      $width = round($width * $percentage);
      $height = round($height * $percentage);
      
      //returns the new sizes in html image tag format...this is so you
      can plug this function inside an image tag and just get the
      
      return "width=\"$width\" height=\"$height\"";
      
      }
      
      ?>
      Before we take our new function on a test drive, we need to get the width and height of the image that we want to display. There is a magical command in PHP called getimagesize(). This command, used properly, will return the image width, height, type, and even the width and height in HTML image tag format (width="x" height="y").

      Code:
      $mysock = getimagesize("images/sock001.jpg");
      Now, $mysock is an array that holds vital information about the particular image we want to display. In index 0, we have the width ($mysock[0]), and in index 1, we have the height ($mysock[1]). That&#39;s really all we need, in order to get what we want done. Want to see the function... well, function? Here we go!
      The Function in Action

      Let&#39;s say you want to display a list of your beautiful socks, but you want room on the page to show them neatly in a row, and to do that they cannot be larger than 150 pixels tall or wide.

      Code:
      <?php
      
      //get the image size of the picture and load it into an array
      $mysock = getimagesize("images/sock001.jpg");
      
      ?>
      <!-using a standard html image tag, where you would have the
      width and height, insert your new imageResize() function with
      the correct attributes -->

      Code:
      [img]images/sock001.jpg[/img]>
      That&#39;s it! Now, no matter what the original file size, it will be restricted to no more than 150 pixels in width or height (or whatever you specify).

      Now, you may think "This sounds too good to be true. Is there any circumstance where using this technique could prove disastrous?"

      Actually, there is. Keep in mind that you aren&#39;t changing the file&#39;s original size. That same 200x400, 50 KB picture you uploaded only moments ago is still 200x400, 50 KB. This script only changes height and width attribute in HTML, so that your original picture conforms to the height and width you think will look best on your Web page.

      Having said that, if you have a page that lists 50-something products, the page will display the way you want it to, but uses will have to download all 50 of those 50 KB pictures, which could take some time. So I&#39;d have to recommend this technique in situations where you&#39;re only showing a few pictures at a time.
      http://ngeo.ro

      Comment


        #4
        this script is on ngeo.ro @ gallery or avatar zone.
        Getting Started[/b]
        if i get tht kind of answer on MY question(s) i would learn PHP in just 1 freakin day!!!!!!!!!!!!!!!!


        nice blackhowk
        sigpiceeeeerrr....

        Comment


          #5
          pmsl rofl
          Want something coded email me at sales@webnwaphost.com for a prices.




          Comment


            #6
            i need an image resizer PHP script that resize images online
            check this script below, it works but only on jpg and jpeg image formats. i need 1 that will work on any image[/b]
            Code:
            <? 
            /* 
            [url]http://www.phpscriptexpert.com/script.php?pn=Image%20Resize%20and%20Watermark&pid=198[/url] 
            */ 
            
            if($_GET[&#39;image&#39;]){ 
                $image = $_GET[&#39;image&#39;]; 
            
                if($_GET[&#39;type&#39;]=="jpg"){ 
                    header("Content-type: image/jpeg"); 
                }elseif($_GET[&#39;type&#39;]=="gif"){ 
                    header("Content-type: image/gif"); 
                }elseif($_GET[&#39;type&#39;]=="png"){ 
                    header("Content-type: image/png"); 
                }else{ 
                    if(substr($image, -3)=="jpg" || substr($image, -3)=="JPG"){header("Content-type: image/jpeg");} 
                    elseif(substr($image, -3)=="gif" || substr($image, -3)=="GIF"){header("Content-type: image/gif");} 
                    elseif(substr($image, -3)=="png" || substr($image, -3)=="PNG"){header("Content-type: image/png");} 
                } 
                 
                if(substr($image, -3)=="jpg" || substr($image, -3)=="JPG"){$im = imagecreatefromjpeg($image);} 
                elseif(substr($image, -3)=="gif" || substr($image, -3)=="GIF"){$im = imagecreatefromgif($image);} 
                elseif(substr($image, -3)=="png" || substr($image, -3)=="PNG"){$im = imagecreatefrompng($image);} 
                 
                if($_GET[&#39;percent&#39;]){ 
                    $x = round((imagesx($im)*$_GET[&#39;percent&#39;])/100); 
                    $y = round((imagesy($im)*$_GET[&#39;percent&#39;])/100); 
                    $yyy=0; 
                    $xxx=0; 
                    $imw = imagecreatetruecolor($x,$y); 
                }elseif($_GET[&#39;w&#39;] and $_GET[&#39;h&#39;]){ 
                    $x = $_GET[&#39;w&#39;]; 
                    $y = $_GET[&#39;h&#39;]; 
                    $yyy=0; 
                    $xxx=0; 
                    $imw = imagecreatetruecolor($x,$y); 
                }elseif($_GET[&#39;maxim_size&#39;]){ 
                    if(imagesy($im)>=$_GET[&#39;maxim_size&#39;] || imagesx($im)>=$_GET[&#39;maxim_size&#39;]){ 
                        if(imagesy($im)>=imagesx($im)){ 
                            $y = $_GET[&#39;maxim_size&#39;]; 
                            $x = ($y*imagesx($im))/imagesy($im); 
                        }else{ 
                            $x = $_GET[&#39;maxim_size&#39;]; 
                            $y = ($x*imagesy($im))/imagesx($im); 
                        } 
                    }else{ 
                        $x = imagesx($im); 
                        $y = imagesy($im); 
                    } 
                    $yyy=0; 
                    $xxx=0; 
                    $imw = imagecreatetruecolor($x,$y); 
                }elseif($_GET[&#39;square&#39;]){ 
                    if(imagesy($im)>=$_GET[&#39;square&#39;] || imagesx($im)>=$_GET[&#39;square&#39;]){ 
                        if(imagesy($im)>=imagesx($im)){ 
                            $x = $_GET[&#39;square&#39;]; 
                            $y = ($x*imagesy($im))/imagesx($im); 
                            $yyy=-($y-$x)/2; 
                            $xxx=0; 
                        }else{ 
                            $y = $_GET[&#39;square&#39;]; 
                            $x = ($y*imagesx($im))/imagesy($im); 
                            $xxx=-($x-$y)/2; 
                            $yyy=0; 
                        } 
                    }else{ 
                        $x = imagesx($im); 
                        $y = imagesy($im); 
                        $yyy=0; 
                        $xxx=0; 
                    } 
                    $imw = imagecreatetruecolor($_GET[&#39;square&#39;],$_GET[&#39;square&#39;]); 
                }else{ 
                    $x = imagesx($im); 
                    $y = imagesy($im); 
                    $yyy=0; 
                    $xxx=0; 
                    $imw = imagecreatetruecolor($x,$y); 
                } 
                 
                imagecopyresampled($imw, $im, $xxx,$yyy,0,0,$x,$y,imagesx($im), imagesy($im)); 
                 
                if($_GET[&#39;watermark_text&#39;]){ 
                    if($_GET[&#39;watermark_color&#39;]){$watermark_color=$_GET[&#39;watermark_color&#39;]; 
                    }else{ 
                        $watermark_color="000000"; 
                    } 
                    $red=hexdec(substr($watermark_color,0,2)); 
                    $green=hexdec(substr($watermark_color,2,2)); 
                    $blue=hexdec(substr($watermark_color,4,2)); 
                     
                    $text_col = imagecolorallocate($imw, $red,$green,$blue); 
                    $font = "georgia.ttf"; //this font(georgia.ttf) heave to be in the same directory as this script 
                    $font_size = 12; 
                    $angle = 0; 
                    $box = imagettfbbox($font_size, $angle, $font, $_GET[&#39;watermark_text&#39;]); 
                    $x = 5; 
                    $y = 17; 
                    imagettftext($imw, $font_size, $angle, $x, $y, $text_col, $font, $_GET[&#39;watermark_text&#39;]); 
            
                } 
                 
                if($_GET[&#39;type&#39;]=="jpg"){imagejpeg($imw);} 
                elseif($_GET[&#39;type&#39;]=="gif"){imagegif($imw);} 
                elseif($_GET[&#39;type&#39;]=="png"){imagepng($imw);} 
                else{ 
                    if(substr($image, -3)=="jpg" || substr($image, -3)=="JPG"){imagejpeg($imw);} 
                    elseif(substr($image, -3)=="gif" || substr($image, -3)=="GIF"){imagegif($imw);} 
                    elseif(substr($image, -3)=="png" || substr($image, -3)=="PNG"){imagepng($imw);} 
                } 
                 
                imagedestroy($imw); 
            } 
            ?>

            Comment


              #7
              Where must those coding should go?

              WapCHAT Forum Currenltly changing over to xhtml

              My Dowloads Site

              Comment


                #8
                Can anybody please help with this? i&#39;m not understanding it...

                WapCHAT Forum Currenltly changing over to xhtml

                My Dowloads Site

                Comment


                  #9
                  create a separate php file for this code
                  Advertise your mobile site for FREE with AdTwirl

                  Comment


                    #10
                    jus use phpthumb can set ouptut format width/height for resizing u only enter height or width as it keeps the aspiration same

                    Comment

                    Working...
                    X