We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Mark Huot's File extension - Code improvements and fixes

Development and Programming

stinhambo's avatar
stinhambo
1,268 posts
16 years ago
stinhambo's avatar stinhambo

I wanted to create a single place for people to access fixes and improvements to Mark Huot’s File extension until Mark is released from his Happy Cog coding cage and he can create an improved version.

If you want to cut and paste any others from the multitude of threads around here then feel free.

This is not a thread for discussing File

This is purely for collation purposes and I am not crediting myself for the original work!

I wanted to start with something that allows File to create JPG thumbnails and adjusts the quality -

Around line #1030 under the heading “Write File”

Change from:

if(@imagegif($dst_img, $dst) !== false) {}
else if(@imagejpeg($dst_img, $dst) !== false) {}
else if(@imagepng($dst_img, $dst) !== false) {}

Change to:

if(@imagejpeg($dst_img, $dst) !== false) {}
else if(@imagegif($dst_img, $dst) !== false) {}
else if(@imagepng($dst_img, $dst) !== false) {}

This will take care of your problem and save your jpeg as a true jpeg. The default image size is set to 60% quality (this is medium in Photoshop)… if you want it set to a higher quality add the number below. (90 means 90% image quality)

if(@imagejpeg($dst_img, $dst, 90) !== false) {}
       
Alex Kendrick's avatar
Alex Kendrick
203 posts
16 years ago
Alex Kendrick's avatar Alex Kendrick

If you have images that are smaller than maximum height or width specified in the file upload preferences, this change will prevent them being enlarged (citation).

is there a way to NOT resize images when the are smapper than Max_width, only if they are larger? Right now it resizes the images to the max_width, even if they are smaller. I need the resize only for larger images.
In ext.mh_file_ext.php, right after the code
//  =============================================
//  Calculate Width/Height
//  =============================================
$dst_x = 0;
$dst_y = 0;                    
$dst_width = ($file_field['max_width']!='')?$file_field['max_width']:$dimensions[0];
$dst_height = ($file_field['max_height']!='')?$file_field['max_height']:$dimensions[1];
insert
if($dst_width > $src_width) {
    $dst_width = $src_width;
}
if($dst_height > $src_height) {
    $$dst_height = $src_height;
}
It will check to see if the original image is smaller than the max width or height. It will still create a thumbnail file with the same dimensions as the original image.
       
John Ryan's avatar
John Ryan
51 posts
16 years ago
John Ryan's avatar John Ryan

If you want to use the file types in your templates, this little addition to the script at about line 1222 will add an extra variable called file_type which will give you the file extension:

$jr_extension = preg_replace('/^.*\./', '', $file); //Add this line
                    $var = array(
                        'count' => $count+1,
                        'total_results' => $total_results,
                        'file_name' => $file,
                        'file_url' => $FNS->remove_double_slashes($file_field['url'].'/'.$file),
                        'file'.$this->thumb_suffix.'_name' => $thumb,
                        'file'.$this->thumb_suffix.'_url' => $thumb_url,
                        'file_type' => $jr_extension //Add this line                    
                    );
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.