SitePoint Sponsor

User Tag List

Page 4 of 6 FirstFirst 123456 LastLast
Results 76 to 100 of 139
  1. #76
    mrc
    SitePoint Community Guest
    The lameness of this script amazes me.

  2. #77
    leo
    SitePoint Community Guest
    1) this can easily be replaced with simple html, but there is a problem with both scripts:

    2) simple resizing will greatly reduce load time, driving customers away from your site. Thumbnails do a much better job of improving load time, even though they are a hassle.

  3. #78
    96rt10
    SitePoint Community Guest
    How did this show up on the first page of my results? I want those 5 minutes of my life back.

  4. #79
    reallyUpset
    SitePoint Community Guest
    This is probably the most narrow solution possible to this problem. Why does Google spit out dated (5+ years) pages for a query whose answer is better served with a more recent page? Kiddies, if you can build your own search engine with a better query analyzer, a billion-dollar market is waiting for you. Google is dead.

  5. #80
    hazree
    SitePoint Community Guest
    There are some error in your script.

    <img src="images/sock001.jpg" <?php imageResize($mysock[0],
    $mysock[1], 150); ?>>

    Correction(put echo before imageresize command)
    <img src="images/sock001.jpg" <?php echo imageResize($mysock[0],
    $mysock[1], 150); ?>>

  6. #81
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jack View Post
    What you can do instead of using up bandwidth is have php resize the image before downloading it eg:
    <?php
    // File and new size
    $filename = 'test.jpg';
    $percent = 0.5;

    // Content type
    header('Content-type: image/jpeg');

    // Get new sizes
    list($width, $height) = getimagesize($filename);
    $newwidth = $width * $percent;
    $newheight = $height * $percent;

    // Load
    $thumb = imagecreate($newwidth, $newheight);
    $source = imagecreatefromjpeg($filename);

    // Resize
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    // Output
    imagejpeg($thumb);
    ?>
    This works nice, but how can I get it to do more than one image (if that's even possible with this code)? I made it into a function and I pass it the image file name and it resizes it. It's simple enough for me but I might be asking it to do too much.

  7. #82
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi etgen (and anyone else!)
    The script above will work but will give you very poor image quality.
    I have changed the script slightly to add imagecreatetruecolor instead of imagecreate.

    To use this on more than one image, you will need to save it as a separate php file eg: thumbnail.php and call it in the <img src> tag

    thumbnail.php
    PHP Code:
    <?php
    // File and new size
    $filename $_GET['img'];
    $percent 0.5;

    // Content type
    header('Content-type: image/jpeg');

    // Get new sizes
    list($width$height) = getimagesize($filename);
    $newwidth $width $percent;
    $newheight $height $percent;

    // Load
    $source imagecreatefromjpeg($filename);
    $thumb imagecreatetruecolor($newwidth$newheight);


    // Resize
    imagecopyresized($thumb$source0000$newwidth$newheight$width$height);

    // Output
    imagejpeg($thumb);
    ?>


    You pass the name of the image (and path) directly to the script and you can also easily change it to take a thumbnail width.

    usage:

    Code:
    <img src="simpleImgResize.php?img=images/myimage.jpg" />
    <img src="simpleImgResize.php?img=images/myotherimage.jpg" />

    HTH

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #83
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot Spike! Works great!

  9. #84
    Mendez
    SitePoint Community Guest
    Spikes works great, but I needed to specify with in pixels (not percentage) and maintain aspect ratio, additionally, not all thumbs would have the same with...(or I could reuse the script for other sites without editing -talk about lazy..tee hee-).

    Here it is:

    <?php
    // File and new size
    $filename = $_GET['img'];

    // Content type
    header('Content-type: image/jpeg');

    // Get new sizes
    list($width, $height) = getimagesize($filename);

    //To specify width
    $newwidth = $_GET['w'];
    $newheight = ($height*$newwidth)/$width;

    // Load
    $source = imagecreatefromjpeg($filename);
    $thumb = imagecreatetruecolor($newwidth, $newheight);

    // Resize
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    // Output
    imagejpeg($thumb);
    ?>

    Usage:

    <img src="thumbnails.php?w=150&img=../images/product/7.2.jpg" />

    Best

    Arturo

  10. #85
    erkan
    SitePoint Community Guest
    i wanna kiss you. but im not gay :) thanks so much :)

  11. #86
    Rusk
    SitePoint Community Guest
    What should I do If I need to resize gif-animated picture? Is it possible in PHP?

  12. #87
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi Rusk, Animated gif's cant be resized in PHP without being 'flattened' into a single image. Not sure if ImageMagick can retain the data or not but you might want to look into it as an option
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  13. #88
    Daquan
    SitePoint Community Guest
    Hello, I'm trying to use this script on a website I'm making. Can anyone help me via email maybe? When I upload the page with the script nothing shows...

  14. #89
    Adam Coppard
    SitePoint Community Guest
    I want to resize images as they are uplaoded, and make the actual image a new size like thumb_imagename etc. So, that then it is safe for use on the web. Is this possible with few modifactions for this script?

  15. #90
    Anonymous Coward
    SitePoint Community Guest
    @ Daquan

    Most likely the script is giving you an error and your server is set not to display errors. The script is giving you and error because when you just copy paste it in, it line breaks and doesn't keep the comment commented!

    Make sure these three lines are also commented:
    //formula accordingly...this is so this script will work
    //dynamically with any size image

    //can plug this function inside an image tag and just get the

    Secondly use standard html comment tags!

    Correct:
    <!-- -->

    Incorrect:
    <!- -->

  16. #91
    aUser
    SitePoint Community Guest
    Does not output anything, please make one that actually works.

  17. #92
    Manuel
    SitePoint Community Guest
    When the pictures get resized they look quite choppy even if u keep the aspect ratio.

    Is there a way to fix that?

  18. #93
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    @Daquan ~ Check as the Anonymous Coward suggested, if it's still not playing - register and start a thread

    @aUser ~ what doesnt output anything? The original script? the script I or Mendez wrote? Be specific!

    @Adam Coppard ~ To save the image instead of serving it as a thumbnail, change the arguments on the imagejpeg function:
    PHP Code:
    /* Save the thumbnail
        **
        ** $thumb = generated image
        ** $filename = location of final image eg 'images/thumbnails/myThumb.jpg
        ** $quality = Quality of the thumbnail; 0 - 100 */

    imagejpeg($thumb$filename$quality); 
    @Manuel ~ The images look choppy because the browser is doing the resizing and browsers aren't supposed to do that. The rendering engine in IE isnt designed to resize images but does the best it can.

    Either manually resize them in photoshop or use the thumbnailing script above
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  19. #94
    SitePoint Evangelist ColinHughes's Avatar
    Join Date
    Sep 2004
    Location
    Spain
    Posts
    468
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not my code!!

    Hi

    I have "inherited" a web site to manage. This site has a problem with the image upload not creating thumbnails but the original designer left no comments as to how he wrote his code.

    I think the problem lies in the following somewhere but I am at a loss as to exactly where. The site stores in a database both reduced size and thumbs for display on a single page.

    Any helpful comments most appreciated.

    PHP Code:
    <?php 

    if($_POST[sbmt]):
                 for(
    $i=0;$i<count($_FILES[foto][tmp_name]);$i++):
                if(
    $_FILES[foto][tmp_name][$i]):
                   
    $r=mysql_query("insert into " $prev "property_pics(id) values (\"" $_REQUEST[id] . "\")");
                    
    $pid=mysql_insert_id();
                   
    $e=explode(".",$_FILES[foto][name][$i]);
                   
    $ext=substr($_FILES[foto][name][$i],-3,3); 
                   
    $size=$foto_size;
                   
    $ext=strtolower($e[1]);
                   if(
    $ext=="peg"){$ext="jpg";}
                   
    copy($_FILES[foto][tmp_name][$i],"../pics/" $pid "." $ext);
                   
    copy($_FILES[foto][tmp_name][$i],"../pics/thumb-" $pid "." $ext);               
                   
    mysql_query("update " $prev "property_pics set file='" .  $pid "." $ext "',thumb='thumb-" $pid "." $ext "' where pid=" $pid);                
                   
    $nw=145;$nh=133;
                   
    $img=$tpath "/thumb-" $pid "." $ext;
                   
    $dimensions GetImageSize($img);
                   
    $thname $img;
                   
    $w=$dimensions[0];
                   
    $h=$dimensions[1];
                   if(
    $ext=="jpg"):
                       
    $img2 ImageCreateFromJpeg($img);
                   elseif(
    $ext=="gif"):
                      
    $img2 ImageCreateFromGif($img);
                   elseif(
    $ext=="png"): 
                      
    $img2 ImageCreateFromPng($img);
                   endif;    
                   
    $thumb=ImageCreateTrueColor($nw,$nh);
                   
    $wm $w/$nw;
                   
    $hm $h/$nh;
         
                    
    $h_height $nh/2;
                   
    $w_height $nw/2;
                   if(
    $w $h)
                   {
                       
    $adjusted_width $w/$hm;
                       
    $half_width $adjusted_width 2;
                       
    $int_width $half_width $w_height;
                       
    ImageCopyResampled($thumb,$img2,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h); 
                       if(
    $ext=="jpg"):
                            
    ImageJPEG($thumb,$thname,95); 
                       elseif(
    $ext=="gif"):
                            
    ImageGIF($thumb,$thname,95); 
                       elseif(
    $ext=="png"): 
                            @
    ImagePNG($thumb,$thname,95); 
                       endif;    
                    }
                    elseif((
    $w $h) || ($w == $h))
                    {
                        
    $adjusted_height $h $wm;
                        
    $half_height $adjusted_height 2;
                        
    $int_height $half_height $h_height;
                        
    ImageCopyResampled($thumb,$img2,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h); 
                        if(
    $ext=="jpg"):
                            
    ImageJPEG($thumb,$thname,95); 
                        elseif(
    $ext=="gif"):
                           
    ImageGIF($thumb,$thname,95); 
                        elseif(
    $ext=="png"): 
                           
    ImagePNG($thumb,$thname,95); 


                        endif;    
                    }
                    else
                    {
                          
    ImageCopyResampled($thumb,$img2,0,0,0,0,$nw,$nh,$w,$h);     
                        if(
    $ext=="jpg"):
                           
    ImageJPEG($thumb,$thname,95); 
                        elseif(
    $ext=="gif"):
                           
    ImageGIF($thumb,$thname,95); 
                        elseif(
    $ext=="png"): 
                             
    ImagePNG($thumb,$thname,95); 
                        endif;    
                     }
                     
    imagedestroy($img2);
                     
                       
    $target=420;
                       
    $img=$tpath "/" $pid "." $ext;
                       
    $dimensions GetImageSize($img);
                       
    $thname $img;
                       
    $w=$dimensions[0];
                       
    $h=$dimensions[1];
                       
    $width=$w;
                       
    $height=$h;
                       if((
    $width>$target && $height>$target) || $width>$target):
                           
    $cent=100-round((($width-$target)/$width)*100);
                           
    $width=round($width*$cent/100);
                           
    $height=round($height*$cent/100);
                       elseif(
    $height>$target):
                           
    $cent=100-round((($height-$target)/$height)*100);
                           
    $width=round($width*$cent/100);
                           
    $height=round($height*$cent/100);
                       endif;
                       if((
    $width>$target && $height>$target)|| $width>$target):
                            
    $cent=100-round((($width-$target)/$width)*100);
                            
    $width =round($width*$cent/100);
                            
    $height=round($height*$cent/100);
                       elseif(
    $height>$target):
                            
    $cent=100-round((($height-$target)/$height)*100);
                            
    $width =round($width*$cent/100);
                            
    $height=round($height*$cent/100);
                       endif;
                       
    $nw=$width;$nh=$height;
                       
                       if(
    $ext=="jpg"):
                           
    $img2 ImageCreateFromJpeg($img);
                       elseif(
    $ext=="gif"):
                          
    $img2 ImageCreateFromGif($img);
                       elseif(
    $ext=="png"): 
                          
    $img2 ImageCreateFromPng($img);
                       endif;    
                       
    $thumb=ImageCreateTrueColor($nw,$nh);
                       
    $wm $w/$nw;
                       
    $hm $h/$nh;
             
                        
    $h_height $nh/2;
                       
    $w_height $nw/2;
                       if(
    $w $h)
                       {
                           
    $adjusted_width $w/$hm;
                           
    $half_width $adjusted_width 2;
                           
    $int_width $half_width $w_height;
                           
    ImageCopyResampled($thumb,$img2,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h); 
                           if(
    $ext=="jpg"):
                                
    ImageJPEG($thumb,$thname,95); 
                           elseif(
    $ext=="gif"):
                                
    ImageGIF($thumb,$thname,95); 
                           elseif(
    $ext=="png"): 
                                
    ImagePNG($thumb,$thname,95); 
                           endif;    
                        }
                        elseif((
    $w $h) || ($w == $h))
                        {
                            
    $adjusted_height $h $wm;
                            
    $half_height $adjusted_height 2;
                            
    $int_height $half_height $h_height;
                            
    ImageCopyResampled($thumb,$img2,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h); 
                            if(
    $ext=="jpg"):
                                
    ImageJPEG($thumb,$thname,95); 
                            elseif(
    $ext=="gif"):
                               
    ImageGIF($thumb,$thname,95); 
                            elseif(
    $ext=="png"): 
                               
    ImagePNG($thumb,$thname,95); 
                            endif;    
                        }
                        else
                        {
                              
    ImageCopyResampled($thumb,$img2,0,0,0,0,$nw,$nh,$w,$h);     
                            if(
    $ext=="jpg"):
                               
    ImageJPEG($thumb,$thname,95); 
                            elseif(
    $ext=="gif"):
                               
    ImageGIF($thumb,$thname,95); 
                            elseif(
    $ext=="png"): 
                                 
    ImagePNG($thumb,$thname,95); 
                            endif;    
                         }
                         
    imagedestroy($img2);
                    endif;
                endfor;
     
                    echo
    "<script>alert('Photo successfully Updated');window.location.href='property.pictures.php?id=" $_REQUEST[id] . "';</script>";        
             endif;      
          
          
    $r=mysql_query("select * from " $prev "property where id="$id);
          
    $d=@mysql_fetch_array($r);
          
    ?>

  20. #95
    SitePoint Member
    Join Date
    Sep 2004
    Location
    india
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Really Good Piece of Code esp. for image Resize, Thank you and God Bless U and I got another solution for image distortion problem, following function will help to create resize the image with good quality and thank to php.net……..

    PHP Code:
    function ThumCreator($ImageSourcePath$ImageDestinationPath$InputWidth$InputHeight$ImageType ""){
            
    $ImageFormat strtolower(substr(strrchr($ImageSourcePath,"."),1));
            switch(
    $ImageFormat){
                case 
    'gif' :
                            
    $SourceType        =    "gif";
                            
    $NewBornImage    =    imagecreatefromgif($ImageSourcePath);
                            break;
                case 
    'png' :
                            
    $SourceType     =    "png";
                            
    $NewBornImage     =     imagecreatefrompng($ImageSourcePath);
                            break;
                case 
    'jpg' :
                            
    $SourceType     =    "jpg";
                            
    $NewBornImage     =    imagecreatefromjpeg($ImageSourcePath);
                            break;
                case 
    'jpeg' :
                            
    $SourceType     =    "jpg";
                            
    $NewBornImage     =    imagecreatefromjpeg($ImageSourcePath);
                            break;
                default :
                            die(
    "ERROR; UNSUPPORTED IMAGE TYPE");
                            break;
              }
        
              list(
    $SourceWidth,$SourceHeight)    =    getimagesize($ImageSourcePath);
                  
    $XOffset    =    0;
                  
    $YOffset     =     0;
              
            if(
    $ImageType == "thumb"){// To minimize destortion
                
    if ($SourceWidth $InputWidth $SourceHeight$InputHeight){
                      
    $XTemp            =    $SourceWidth;
                      
    $XRatio         =     1-((($SourceWidth/$SourceHeight)-($InputWidth/$InputHeight))/2);
                      
    $SourceWidth     =     $SourceWidth $XRatio;
                      
    $XOffset         =     ($XTemp $SourceWidth)/2;
                }elseif(
    $SourceHeight$InputHeight $SourceWidth $InputWidth){
                    
    $YTemp             =     $SourceHeight;
                    
    $YRatio         =     1-((($InputWidth/$InputHeight)-($SourceWidth/$SourceHeight))/2);
                    
    $SourceHeight     =     $SourceHeight $YRatio;
                    
    $YOffset         =     ($YTemp $SourceHeight)/2;
                }
           }else{ 
    //Added this else part -------------    
                
    $XTemp                 =     $SourceWidth/$InputWidth;
                
    $NewWidth             =     $InputWidth;
                
    $NewHeight             =     $SourceHeight/$XTemp;
                if (
    $NewHeight $InputHeight){
                    
    $YTemp             =     $SourceHeight/$InputHeight;
                    
    $NewHeight         =     $InputHeight;
                    
    $NewWidth         =     $SourceWidth/$YTemp;
                }
                
    $InputWidth         =    round($NewWidth);
                
    $InputHeight         =     round($NewHeight);
          }
          
        
          
    $DestinationImage    =    imagecreatetruecolor ($InputWidth$InputHeight);
          
    imagecopyresampled($DestinationImage$NewBornImage00$XOffset$YOffset$InputWidth$InputHeight$SourceWidth$SourceHeight);
        
          if(
    $SourceType=="gif"){
              
    imagegif($DestinationImage,$ImageDestinationPath);
          }elseif(
    $SourceType=="jpg"){
            
    imagejpeg($DestinationImage$ImageDestinationPath);
          }elseif(
    $SourceType=="png"){
            
    imagepng($DestinationImage$ImageDestinationPath);
          }elseif(
    $SourceType=="bmp"){
            
    imagewbmp($DestinationImage$ImageDestinationPath);
          }
          return 
    true;
        } 
    Regards

    sujith
    http://sujithfem.byethost32.com
    http://suzerain.isgreat.org/
    http://oxygen.isgreat.org/
    Last edited by sujithfem; May 30, 2008 at 01:26.
    "The fear of the Lord is the beginning of wisdom"

  21. #96
    SitePoint Member
    Join Date
    Jun 2008
    Location
    Stockholm
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great code and works like it should.

  22. #97
    Mike
    SitePoint Community Guest
    I just wanted to say that I thought this was an awesome tutorial... I was getting ready to write my very own from scratch, but decided to have a look and see if someone else had already done it and make a tutorial... sure enough, you had and it was very well explained and laid out... Thank you.

  23. #98
    Programmer
    SitePoint Community Guest
    Wow. This is a total hack job solution!

  24. #99
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Script is amazingly simple, but once again you gotta way the benefits of it vs the long term affects.
    It's super simple to implement, but creates way to much over head. Yeah there's not much over head here, but if you upload the image in correct size than there is no need for this. If you're saying this isn't possible than use an image resize script.

  25. #100
    SitePoint Member jellen's Avatar
    Join Date
    Jul 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I usually use programm to resize my pictures,then upload the pictures to my host! Picture Resize Genius is a good choice, I usually batch resize my photos,it is fit for me;


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
  •