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) {}
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 codeinsert// ============================================= // 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];
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.if($dst_width > $src_width) { $dst_width = $src_width; } if($dst_height > $src_height) { $$dst_height = $src_height; }
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
);
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.