Page 2 of 2 First 12
  1. #16
    Huey's Avatar
    Registered
    27/08/06
    Location
    Antwerp City
    Posts
    495
    iTrader
    2 (100%)
    Mentioned
    0 Post(s)
    Ik heb echt geen idee wat ik moet doen man
    Bestaat hier echt geen ander gratis script voor ofzo?
    no votes  

  2. #17
    tha_rippa1be's Avatar
    Registered
    23/05/03
    Location
    Stavanger
    Posts
    1,837
    iTrader
    10 (100%)
    Mentioned
    0 Post(s)
    Reputation
    1/4
    Quote Originally Posted by Huey View Post
    This quote is hidden because you are ignoring this member. Show
    Ik heb echt geen idee wat ik moet doen man
    Bestaat hier echt geen ander gratis script voor ofzo?
    Dit ist geen dat ik ineen had geflanst:
    Kan hoogst waarschijnlijk veel aan verbeterd worden, maar het werkt.
    (een afbeelding inlezen van BMP werkt bvb niet, opslaan als BMP dan weer wel.)
    PHP Code:
    class Image{
            public function 
    Image($pathToImage){
                
    $this->pathToImage $pathToImage;
                list(
    $this->width$this->height) = getimagesize($pathToImage);
                
                
    //find the input filetype
                
    $this->filetype pathinfo($pathToImage);
                
    $this->filetype $this->filetype['extension'];
                
                
    $this->setOutputQuality(100);
                
    $this->image $this->createImage();
            }
            
            public function 
    setOutputQuality($quality){
                
    //0 <= quality  <= 100
                
    if($this->filetype == 'jpg' || $this->filetype == 'jpeg'){
                    
    //its jpeg (quality means: ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). The default is the default IJG quality value (about 75).)
                    
    $this->outputQuality $quality;
                }else{
                    
    //its png (quality means: Compression level: from 0 (no compression) to 9.)
                    
    $this->outputQuality = (10-$quality/10 <= 9)?10-$quality/109;
                }
            }
            
            private function 
    createImage(){
                switch(
    $this->filetype){
                    case 
    'png':
                        return 
    imagecreatefrompng($this->pathToImage);
                    break;
                    case 
    'jpg':
                        return 
    imagecreatefromjpeg($this->pathToImage);
                    break;
                    case 
    'jpeg':
                        return 
    imagecreatefromjpeg($this->pathToImage);
                    break;
                    case 
    'gif':
                        return 
    imagecreatefromgif($this->pathToImage);
                    break;
                    case 
    'bmp'//errort
                        
    return imagecreatefromwbmp($this->pathToImage);
                    break;
                }
            }
            
            private function 
    saveImage($image$location){
                
    $filetype pathinfo($location);
                
    $filetype $filetype['extension'];
                
                switch(
    $filetype){
                    case 
    'png':
                        
    imagepng($image$location$this->outputQuality);
                    break;
                    case 
    'jpg':
                        
    imagejpeg($image$location$this->outputQuality);
                    break;
                    case 
    'jpeg':
                        
    imagejpeg($image$location$this->outputQuality);
                    break;
                    case 
    'gif':
                        
    imagegif($image$location);
                    break;
                    case 
    'bmp':
                        
    imagewbmp($image$location);
                    break;
                }
            }
            
            public function 
    saveResizedBySizeCrop($pathToNewImage$newWidth$newHeight){
                
    $calculatedWidth $newWidth;
                
    $calculatedHeight $newHeight;
                
    $xOffset 0;
                
    $yOffset 0;
                if(
    $this->width/$newWidth $this->height/$newHeight){
                    
    $calculatedHeight $this->height/($this->width/$newWidth);
                    
    $yOffset = ($calculatedHeight-$newHeight)/2;
                }elseif(
    $this->width/$newWidth $this->height/$newHeight){
                    
    $calculatedWidth $this->width/$this->height*$newHeight;
                    
    $xOffset = ($calculatedWidth-$newWidth)/2;
                }
    //else the ratio is correct, keep the newWidth and newHeight and 0 offset
                
                
    $resizedImage imagecreatetruecolor($newWidth$newHeight);
                
    imagecopyresampled($resizedImage$this->image0-$xOffset0-$yOffset00$calculatedWidth$calculatedHeight$this->width$this->height);
                
                
    $this->saveImage($resizedImage$pathToNewImage);
                
    imagedestroy($resizedImage);
            }
            
            public function 
    saveResizedByWidth($pathToNewImage$newWidth){
                
    $this->saveResizedBySizeCrop($pathToNewImage$newWidth$this->height/$this->width*$newWidth);
            }
            
            public function 
    saveResizedByHeight($pathToNewImage$newHeight){
                
    $this->saveResizedBySizeCrop($pathToNewImage$this->width/$this->height*$newHeight$newHeight);
            }
        } 
    gebruik:
    PHP Code:
    $imjpg = new Image("in/in.jpg");
    $imjpg->saveResizedByWidth("out.jpg"300);

    $imjpeg= new Image("in/in.jpeg");
    $imjpeg->saveResizedByWidth("out.jpeg"300);

    $imgif = new Image("in/in.gif");
    $imgif->saveResizedByWidth("out.gif"300);

    $impng = new Image("in/in.png");
    $impng->saveResizedByWidth("out.png"300);

    $impng = new Image("in/in.png");
    $impng->setOutputQuality(50); //van 0-100 (hoger is beter)
    $impng->saveResizedBySize("smalltobig.png"1000500
    Last edited by tha_rippa1be; 09-01-2009 at 21:31.

    no votes  

  3. #18
    dJeez's Avatar
    Registered
    17/07/02
    Location
    Sol System
    Posts
    10,064
    iTrader
    1 (100%)
    Mentioned
    0 Post(s)
    Reputation
    27/78
    Hier is +/- wat ik gebruikte op Vande Moortel :
    PHP Code:
    function generate_thumbnail($source$dest$target_size)
    {
        if (!
    file_exists($source))
        {
            throw new 
    Exception("Couldn't locate file '$source'.");
        }
        
    $info getimagesize($source);

        
    $newwidth $info[0];
        
    $newheight $info[1];

        
    // resize
        
    if ($newwidth $newheight)
        {
            
    $xstart 0;
            
    $ystart round(($newheight-$newwidth)/2);
            
    $xstop $newwidth;
            
    $ystop $newwidth;
        }
        else if (
    $newwidth $newheight)
        {
            
    $xstart round(($newwidth-$newheight)/2);
            
    $ystart 0;
            
    $xstop $newheight;
            
    $ystop $newheight;
        }
        else
        {
            
    $xstart 0;
            
    $ystart 0;
            
    $xstop $newwidth;
            
    $ystop $newheight;
        }

        switch(
    $info[2])
        {
            case 
    IMG_GIF:
                
    $original imagecreatefromgif($source);
                if (!
    $original)
                {
                    throw new 
    Exception("Couldn't open GIF '$source'.");
                }
                
    $thumbnail imagecreate($target_size$target_size);
                
    imagecopyresampled($thumbnail$original00$xstart$ystart$target_size$target_size$xstop$ystop);
                
    imagegif($thumbnail$dest);
                break;
            case 
    IMG_JPG:
            case 
    IMG_JPEG:
                
    $original imagecreatefromjpeg($source);
                if (!
    $original)
                {
                    throw new 
    Exception("Couldn't open jpeg '$source'.");
                }
                
    $thumbnail imagecreatetruecolor($target_size$target_size);
                
    imagecopyresampled($thumbnail$original00$xstart$ystart$target_size$target_size$xstop$ystop);
                
    imagejpeg($thumbnail$dest);
                break;
            case 
    IMG_PNG:
                
    $original imagecreatefrompng($source);
                if (!
    $original)
                {
                    throw new 
    Exception("Couldn't open PNG '$source'.");
                }
                
    $thumbnail imagecreatetruecolor($target_size$target_size);
                
    imagecopyresampled($thumbnail$original00$xstart$ystart$target_size$target_size$xstop$ystop);
                
    imagepng($thumbnail$dest);
                break;
        }

        return 
    TRUE;

    De parameters zijn respectievelijk de bestandsnaam van het originele bestand, die van de thumbnail en de dimensie van de thumbnail (in dit geval een vierkant, dus ook maar 1 parameter ).

    Misschien kan je best ook een chmod doen van de afbeelding na het wegschrijven zodat die via FTP verwijderbaar is (0644 should do the trick).
    PSN: dJeezBE - Delicious bookmarks
    Disclaimer: I am currently suffering from severe CSD (Compulsive Sarcasm Disorder). - L'onion fait la farce - Facile largire de alieno
    Pastafarian by choice
    no votes  

  4. #19
    FurtiveDuck's Avatar
    Registered
    04/10/03
    Location
    9000
    Posts
    3,755
    iTrader
    14 (100%)
    Mentioned
    0 Post(s)
    Reputation
    5/35
    Misschien es checken in de broncode van netlog?
    no votes  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in