Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation JPEG image limit... Re-Written GIF & PNG's? Help!

    Well here's my problem... i need to be able to upload every type of image to my website, i use a CMS system and it has a limit at JPG.. i only ever use GIF & PNG's...

    Here's the code from my uploading page that detects the image type etc..

    If you need any other bits of code please tell me n ill post them up..

    Can this be re-written to accept all types of images and thumbnail them etc or is it 'locked' to only do JPEG...

    ANY advice would really help me as im getting despirate, as you can see im no scripter and your help is much appreciated!

    Thanks in advance,
    Chris

    PHP Code:
    if($Submit){

        
    // Check to make sure file is an acceptable jpg
        
    if (eregi ("(.)+\\.(jp(e){0,1}g$)"strtolower($File_name))){

            
    $query "SELECT * FROM $DB_Projects ORDER BY id DESC LIMIT 0,1";
            
    $result mysql_query($query$Link) or queryError("12"mysql_error());
            if(
    mysql_num_rows($result)){
                
    $ROW mysql_fetch_object($result);
                
    $filename = ($ROW->id 1) . ".jpg";
            }
            else 
    $filename "1.jpg";
            
            if (@
    copy($File$admin_location_photo.$filename)){
                
                
    // size max width or height - 1 to trim mishap edges
                
    $size_thumb $sxThemeConfig['GalleryMaxDimensionThumb'] - 1;
                
    $size_scaled $sxThemeConfig['GalleryMaxDimensionProject'] - 1;
                
                
    $compression_thumb $sxThemeConfig['GalleryCompressionThumb'];
                
    $compression_scaled $sxThemeConfig['GalleryCompressionProject'];
                
                if((
    imageCompatibility() == "truecolor")OR(imageCompatibility() == "normal")){
                    
    $image imagecreatefromjpeg($admin_location_photo.$filename);
                    
    $width_original imagesx($image);
                    
    $height_original imagesy($image);
                }
                elseif(
    imageCompatibility() == "imagemagick"){
                    
    $image imagick_readimage($admin_location_photo.$filename);
                    
    $width_original imagick_sample($image'width');
                    
    $height_original imagick_sample($image'height');
                }
                
                
    $filesize_original filesize($admin_location_photo.$filename);
                
                
    // Dimension change needed
                
    if(($width_original $size_scaled)OR($height_original $size_scaled)){
                
                    
    $dimensions resizeDimensions($width_original$height_original$size_scaled);
                    
                    if(
    imageCompatibility() == "truecolor"){
                        
    $image_new imagecreatetruecolor($dimensions[0]+1$dimensions[1]+1);
                        
    imagecopyresampled($image_new$image0000$dimensions[0]+1$dimensions[1]+1$width_original$height_original);
                        
    imagejpeg($image_new$admin_location_photo_scaled.$filename$compression_scaled);
                        
    imagedestroy($image_new);
                    }
                    elseif(
    imageCompatibility() == "normal"){
                        
    $image_new imagecreate($dimensions[0]+1$dimensions[1]+1);
                        
    imagecopyresized($image_new$image0000$dimensions[0]+1$dimensions[1]+1$width_original$height_original);
                        
    imagejpeg($image_new$admin_location_photo_scaled.$filename$compression_scaled);
                        
    imagedestroy($image_new);
                    }
                    elseif(
    imageCompatibility() == "imagemagick"){
                        
    $image_new imagick_readimage($admin_location_photo.$filename);
                        
    imagick_sample($image_new$dimensions[0]+1$dimensions[1]+1);
                        
    imagick_writeimage($image_new$admin_location_photo_scaled.$filename);
                    }
                                                    
                    
    $filesize filesize($admin_location_photo_scaled.$filename);
                    
    $width $dimensions[0] + 1;
                    
    $height $dimensions[1] + 1;
                    
                }else{
                    @
    copy($admin_location_photo.$filename$admin_location_photo_scaled.$filename);
                    
    $filesize filesize($admin_location_photo_scaled.$filename);
                    
    $width $width_original;
                    
    $height $height_original;
                }
                
                
    $dimensions resizeDimensions($width_original$height_original$size_thumb);
                
                if(
    imageCompatibility() == "truecolor"){
                    
    $image_new_thumb imagecreatetruecolor($dimensions[0]+1$dimensions[1]+1);
                    
    imagecopyresampled($image_new_thumb$image0000$dimensions[0]+1$dimensions[1]+1$width_original$height_original);
                    
    imagejpeg($image_new_thumb$admin_location_thumbnail.$filename$compression_thumb);
                    
    imagedestroy($image_new_thumb);
                }
                elseif(
    imageCompatibility() == "normal"){
                    
    $image_new_thumb imagecreate($dimensions[0]+1$dimensions[1]+1);
                    
    imagecopyresized($image_new_thumb$image0000$dimensions[0]+1$dimensions[1]+1$width_original$height_original);
                    
    imagejpeg($image_new_thumb$admin_location_thumbnail.$filename$compression_thumb);
                    
    imagedestroy($image_new_thumb);
                }
                elseif(
    imageCompatibility() == "imagemagick"){
                    
    $image_new_thumb imagick_readimage($admin_location_photo.$filename);
                    
    imagick_sample($image_new_thumb$dimensions[0]+1$dimensions[1]+1);
                    
    imagick_writeimage($image_new_thumb$admin_location_thumbnail.$filename);
                }            
                
                if(
    $sxSetup['AdvancedProjectMode']){
                    
    $width_final $width_original;
                    
    $height_final $height_original;
                    
    $filesize_final $filesize_original;
                    
    $original 1;
                }else{
                    @
    unlink($admin_location_photo.$filename);
                    
    $width_final $width;
                    
    $height_final $height;
                    
    $filesize_final $filesize;
                    
    $orignial 0;
                } 

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,096
    Thanks
    11
    Thanked 101 Times in 99 Posts
    might be easier to just convert the uploaded file to a jpeg before you pass it to your function ... if you have imagemagick installed
    PHP Code:
    <?exec("convert $uploaded_filename newfile.jpg");?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sounds like a good idea to me... as i said im no scripter so can you insert that into my existing code please?

    Thanks alot,
    Chris


  •  

    Posting Permissions

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