Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1218400
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Nov 13, 3:02 PM
Size
3 KB
Mime Type
text/x-diff
Expires
Sat, Nov 15, 3:02 PM (1 h, 54 m)
Engine
blob
Format
Raw Data
Handle
796668
Attached To
rINP In-Portal
in-portal
View Options
Index: branches/unlabeled/unlabeled-1.1.2/kernel/units/general/image_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.1.2/kernel/units/general/image_helper.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.1.2/kernel/units/general/image_helper.php (revision 4116)
@@ -0,0 +1,120 @@
+<?php
+
+class kImageHelper extends kHelper {
+
+ var $Image;
+ var $FileName;
+ var $ImageInfo;
+
+ function Load($file_name)
+ {
+ $image_info = getimagesize($file_name);
+
+ list($orig_width, $orig_height, $type, $attr) = $image_info;
+ $type = $image_info['mime'];
+
+ $type_to_function = Array(
+ 'image/jpeg' => 'imagecreatefromjpeg',
+ 'image/pjpeg' => 'imagecreatefromjpeg',
+ 'image/png' => 'imagecreatefrompng',
+ 'image/gif' => 'imagecreatefromgif',
+ );
+ $func_to_use = $type_to_function[$type];
+
+ $this->ImageInfo = $image_info;
+ $this->FileName = $file_name;
+ return ( $this->Image = @$func_to_use($file_name) ) ? 1 : 0;
+ }
+
+ function CopyResizedWithBackground($max_width, $max_height, $quality, $bg_color = false, $target_filename = false)
+ {
+ list($orig_width, $orig_height, $type, $attr) = $this->ImageInfo;
+
+ $dst_img = imagecreatetruecolor($max_width, $max_height);
+
+ if(!is_array($bg_color))
+ {
+ $bg_color = Array(0xFF, 0xFF, 0xFF);
+ }
+
+ list($r, $g, $b) = $bg_color;
+ $bg_color = imagecolorallocate($dst_img, $r, $g, $b);
+ imagefill($dst_img, 0 ,0, $bg_color);
+
+ $too_large = ($orig_width > $max_width) || ($orig_height > $max_height);
+
+ if($too_large)
+ {
+ $width_ratio = $max_width ? $max_width / $orig_width : 1;
+ $height_ratio = $max_height ? $max_height / $orig_height : 1;
+ $ratio = min($width_ratio, $height_ratio);
+
+ $width = ceil($orig_width * $ratio);
+ $height = ceil($orig_height * $ratio);
+ }
+ else
+ {
+ $width = $orig_width;
+ $height = $orig_height;
+ }
+
+ $dst_x = ceil(($max_width - $width) / 2);
+ $dst_y = ceil(($max_height - $height) / 2);
+ imagecopyresampled($dst_img, $this->Image, $dst_x, $dst_y, 0, 0, $width, $height, $orig_width, $orig_height);
+
+ if($target_filename)
+ {
+ imagejpeg($dst_img, $target_filename, $quality);
+ }
+ else
+ {
+ $this->Image = $dst_img;
+ }
+ }
+
+ function CopyResized($max_width, $max_height, $quality, $target_filename = false)
+ {
+ list($orig_width, $orig_height, $type, $attr) = $this->ImageInfo;
+
+ $too_large = ($orig_width > $max_width) || ($orig_height > $max_height);
+
+ if($too_large)
+ {
+ $width_ratio = $max_width ? $max_width / $orig_width : 1;
+ $height_ratio = $max_height ? $max_height / $orig_height : 1;
+ $ratio = min($width_ratio, $height_ratio);
+
+ $width = ceil($orig_width * $ratio);
+ $height = ceil($orig_height * $ratio);
+ }
+ else
+ {
+ $width = $orig_width;
+ $height = $orig_height;
+ }
+
+ $dst_img = imagecreatetruecolor($width, $height);
+
+ imagecopyresampled($dst_img, $this->Image, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height);
+
+ if($target_filename)
+ {
+ imagejpeg($dst_img, $target_filename, $quality);
+ }
+ else
+ {
+ $this->Image = $dst_img;
+ }
+ }
+
+ function SaveImage($quality, $file_name = false)
+ {
+ if(!$file_name)
+ {
+ $file_name = $this->FileName;
+ }
+ imagejpeg($this->Image, $file_name, $quality);
+ }
+}
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.1.2/kernel/units/general/image_helper.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1.2.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Event Timeline
Log In to Comment