Class upload
What does it do?
It manages file uploads for you. In short, it manages the uploaded file, and allows you to do whatever you want with the file, especially if it is an image, and as many times as you want.
It is the ideal class to quickly integrate file upload in your site. If the file is an image, you can convert, resize, crop it in many ways. You can also apply filters, add borders, text, watermarks, etc... That's all you need for a gallery script for instance. Supported formats are PNG, JPG, GIF and BMP.
You can also use the class to work on local files, which is especially useful to use the image manipulation features. The class also supports Flash uploaders.
The class works with PHP 4 and 5, and its error messages can be localized at will.
How does it work?
You instanciate the class with the $_FILES['my_field'] array where my_field is the field name from your upload form. The class will check if the original file has been uploaded to its temporary location (alternatively, you can instanciate the class with a local filename).
You can then set a number of processing variables to act on the file. For instance, you can rename the file, and if it is an image, convert and resize it in many ways. You can also set what will the class do if the file already exists.
Then you call the function process to actually perform the actions according to the processing parameters you set above. It will create new instances of the original file, so the original file remains the same between each process. The file will be manipulated, and copied to the given location. The processing variables will be reset once it is done.
You can repeat setting up a new set of processing variables, and calling process again as many times as you want. When you have finished, you can call clean to delete the original uploaded file.
If you don't set any processing parameters and call process just after instanciating the class. The uploaded file will be simply copied to the given location without any alteration or checks.
Don't forget to add enctype="multipart/form-data" in your form tag <form> if you want your form to upload the file.
How to use it?
Create a simple HTML file, with a form such as:
<form enctype="multipart/form-data" method="post" action="upload.php"> <input type="file" size="32" name="image_field" value=""> <input type="submit" name="Submit" value="upload"> </form>Create a file called upload.php:
$handle = new upload($_FILES['image_field']);
if ($handle->uploaded) {
$handle->file_new_name_body = 'image_resized';
$handle->image_resize = true;
$handle->image_x = 100;
$handle->image_ratio_y = true;
$handle->process('/home/user/files/');
if ($handle->processed) {
echo 'image resized';
$handle->clean();
} else {
echo 'error : ' . $handle->error;
}
}How to process local files?
Use the class as following, the rest being the same as above:
$handle = new upload('/home/user/myfile.jpg');How to set the language?
Instantiate the class with a second argument being the language code:
$handle = new upload($_FILES['image_field'], 'fr_FR');
$handle = new upload('/home/user/myfile.jpg', 'fr_FR');How to output the resulting file or picture directly to the browser?
Simply call process() without an argument (or with null as first argument):
$handle = new upload($_FILES['image_field']);
header('Content-type: ' . $handle->file_src_mime);
echo $handle->Process();
die(); Or if you want to force the download of the file: $handle = new upload($_FILES['image_field']);
header('Content-type: ' . $handle->file_src_mime);
header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";");
echo $handle->Process();
die();Processing parameters (reset after each process)
$handle->file_new_name_body = 'new name';
$handle->file_name_body_add = '_uploaded';
$handle->file_name_body_pre = 'thumb_';
$handle->file_new_name_ext = 'txt';
$handle->file_safe_name = true;
$handle->file_overwrite = true;
$handle->file_auto_rename = true;
$handle->auto_create_dir = true;
$handle->dir_auto_chmod = true;
$handle->dir_chmod = 0777;
$handle->file_max_size = '1024'; // 1KB
$handle->mime_check = true;
$handle->no_script = false;
$handle->allowed = array('application/pdf','application/msword', 'image/*');$handle->forbidden = array('application/*');$handle->image_convert = 'jpg';
$handle->image_background_color = '#FF00FF';
$handle->image_default_color = '#FF00FF';
$handle->jpeg_quality = 50;
$handle->jpeg_size = 3072;
$handle->image_max_width = 200;
$handle->image_max_height = 100;
$handle->image_max_pixels = 50000;
$handle->image_max_ratio = 1.5;
$handle->image_min_width = 100;
$handle->image_min_height = 500;
$handle->image_min_pixels = 20000;
$handle->image_min_ratio = 0.5;
$handle->image_resize = true;
$handle->image_x = 100;
$handle->image_y = 200;
$handle->image_ratio = true;
$handle->image_ratio_crop = true;
$handle->image_ratio_fill = true;
$handle->image_ratio_no_zoom_in = true;
$handle->image_ratio_no_zoom_out = true;
$handle->image_ratio_x = true;
$handle->image_ratio_y = true;
$handle->image_ratio_pixels = 25000;
$handle->image_brightness = 40;
$handle->image_contrast = 50;
$handle->image_tint_color = '#FF0000';
$handle->image_overlay_color = '#FF0000';
$handle->image_overlay_percent = 20;
$handle->image_negative = true;
$handle->image_greyscale = true;
$handle->image_threshold = 20;
$handle->image_unsharp = true;
$handle->image_unsharp_amount = 120;
$handle->image_unsharp_radius = 0.8;
$handle->image_unsharp_threshold = 0;
$handle->image_text = 'test';
$handle->image_text_direction = 'v';
$handle->image_text_color = '#FF0000';
$handle->image_text_percent = 50;
$handle->image_text_background = '#FFFFFF';
$handle->image_text_background_percent = 50;
$handle->image_text_font = 4;
$handle->image_text_x = 5;
$handle->image_text_y = 5;
$handle->image_text_position = 'LR';
$handle->image_text_padding = 5;
$handle->image_text_padding_x = 2;
$handle->image_text_padding_y = 10;
$handle->image_text_alignment = 'R';
$handle->image_text_line_spacing = 3;
$handle->image_flip = 'h';
$handle->image_rotate = 90;
$handle->image_crop = array(50,40,30,20); OR '-20 20%'...
$handle->image_precrop = array(50,40,30,20); OR '-20 20%'...
$handle->image_bevel = 20;
$handle->image_bevel_color1 = '#FFFFFF';
$handle->image_bevel_color2 = '#000000';
$handle->image_border = '3px'; OR '-20 20%' OR array(3,2)...
$handle->image_border_color = '#FFFFFF';
$handle->image_frame = 2;
$handle->image_frame_colors = array('#999999', '#FF0000', '#666666', '#333333', '#000000');$handle->image_watermark = 'watermark.png';
$handle->image_watermark_x = 5;
$handle->image_watermark_y = 5;
$handle->image_watermark_position = 'LR';
$handle->image_watermark_no_zoom_in = false;
$handle->image_watermark_no_zoom_out = true;
$handle->image_reflection_height = '25%';
$handle->image_reflection_space = 3;
$handle->image_default_color = '#000000';
$handle->image_reflection_opacity = 60;
Values that can be read before calling process()
Values that can be read after calling process()
Requirements
Most of the image operations require GD. GD2 is greatly recommended
The class is compatible with PHP 4.3+, and compatible with PHP5
Changelog
array
$allowed
(line 2012)
Allowed MIME types
Default is a selection of safe mime-types, but you might want to change it
Simple wildcards are allowed, such as image/* or application/*
bool
$dir_auto_chmod
(line 951)
Set this variable to true to allow automatic chmod of the destination directory if it is not writeable
Default value is true
bool
$dir_auto_create
(line 940)
Set this variable to true to allow automatic creation of the destination directory if it is missing (works recursively)
Default value is true
bool
$dir_chmod
(line 962)
Set this variable to the default chmod you want the class to use when creating directories, or attempting to write in a directory
Default value is 0777 (without quotes)
string
$error
(line 786)
Holds eventual error message in plain english
bool
$file_auto_rename
(line 929)
Set this variable to true to allow automatic renaming of the file if the file already exists
Default value is true
For instance, on uploading foo.ext,
if foo.ext already exists, upload will be renamed foo_1.ext
and if foo_1.ext already exists, upload will be renamed foo_2.ext
Note that this option doesn't have any effect if file_overwrite is true
string
$file_dst_name
(line 647)
Destination file name
string
$file_dst_name_body
(line 655)
Destination file name body (i.e. without extension)
string
$file_dst_name_ext
(line 663)
Destination file extension
string
$file_dst_path
(line 639)
Destination file name
string
$file_dst_pathname
(line 671)
Destination file name, including path
boolean
$file_is_image
(line 743)
Flag to determine if the source file is an image
double
$file_max_size
(line 982)
Set this variable to change the maximum size in bytes for an uploaded file
Default value is the value upload_max_filesize from php.ini
string
$file_name_body_add
(line 814)
Set this variable to append a string to the file name body
string
$file_name_body_pre
(line 822)
Set this variable to prepend a string to the file name body
string
$file_new_name_body
(line 806)
Set this variable to replace the name body (i.e. without extension)
string
$file_new_name_ext
(line 830)
Set this variable to change the file extension
bool
$file_overwrite
(line 972)
Set this variable tu true to allow overwriting of an existing file
Default value is false, so no files will be overwritten
boolean
$file_safe_name
(line 838)
Set this variable to format the filename (spaces changed to _)
string
$file_src_error
(line 615)
Holds eventual PHP error code from $_FILES
string
$file_src_mime
(line 599)
Uploaded file MIME type
string
$file_src_name
(line 567)
Uploaded file name
string
$file_src_name_body
(line 575)
Uploaded file name body (i.e. without extension)
string
$file_src_name_ext
(line 583)
Uploaded file name extension
string
$file_src_name_ext_
(line 591)
Uploaded file name extension, original
string
$file_src_pathname
(line 623)
Uloaded file name, including server path
double
$file_src_size
(line 607)
Uploaded file size, in bytes
array
$forbidden
(line 2025)
Forbidden MIME types
Default is a selection of safe mime-types, but you might want to change it To only check for forbidden MIME types, and allow everything else, set allowed to array('* / *') without the spaces
Simple wildcards are allowed, such as image/* or application/*
string
$image_background_color
(line 1278)
Background color, used to paint transparent areas with
If set, it will forcibly remove transparency by painting transparent areas with the color This setting will fill in all transparent areas in PNG and GIF, as opposed to image_default_color which will do so only in BMP, JPEG, and alpha transparent areas in transparent GIFs This setting overrides image_default_color
Default value is null
integer
$image_bevel
(line 1806)
Adds a bevel border on the image
Value is a positive integer, representing the thickness of the bevel
If the bevel colors are the same as the background, it makes a fade out effect
Default value is null (no bevel)
string;
$image_bevel_color1
(line 1819)
Top and left bevel color
Value is a color, in hexadecimal format This setting is used only if image_bevel is set
Default value is #FFFFFF
string;
$image_bevel_color2
(line 1832)
Right and bottom bevel color
Value is a color, in hexadecimal format This setting is used only if image_bevel is set
Default value is #000000
integer
$image_border
(line 1852)
Adds a single-color border on the outer of the image
Values are four dimensions, or two, or one (CSS style) They represent the border thickness top, right, bottom and left. These values can either be in an array, or a space separated string. Each value can be in pixels (with or without 'px'), or percentage (of the source image)
See image_crop for valid formats
If a value is negative, the image will be cropped. Note that the dimensions of the picture will be increased by the borders' thickness
Default value is null (no border)
string;
$image_border_color
(line 1865)
Border color
Value is a color, in hexadecimal format. This setting is used only if image_border is set
Default value is #FFFFFF
integer
$image_brightness
(line 1314)
Corrects the image brightness
Value can range between -127 and 127
Default value is null
integer
$image_contrast
(line 1326)
Corrects the image contrast
Value can range between -127 and 127
Default value is null
string
$image_convert
(line 1007)
Set this variable to convert the file if it is an image
Possibles values are : ''; 'png'; 'jpeg'; 'gif'; 'bmp'
Default value is '' (no conversion)
If resize is true, convert will be set to the source file extension
string
$image_crop
(line 1780)
Crops an image
Values are four dimensions, or two, or one (CSS style) They represent the amount cropped top, right, bottom and left. These values can either be in an array, or a space separated string. Each value can be in pixels (with or without 'px'), or percentage (of the source image)
For instance, are valid:
$foo->image_crop = 20 OR array(20);
$foo->image_crop = '20px' OR array('20px');
$foo->image_crop = '20 40' OR array('20', 40);
$foo->image_crop = '-20 25%' OR array(-20, '25%');
$foo->image_crop = '20px 25%' OR array('20px', '25%');
$foo->image_crop = '20% 25%' OR array('20%', '25%');
$foo->image_crop = '20% 25% 10% 30%' OR array('20%', '25%', '10%', '30%');
$foo->image_crop = '20px 25px 2px 2px' OR array('20px', '25%px', '2px', '2px');
$foo->image_crop = '20 25% 40px 10%' OR array(20, '25%', '40px', '10%');If a value is negative, the image will be expanded, and the extra parts will be filled with black
Default value is null (no cropping)
boolean
$image_default_color
(line 1294)
Default color for non alpha-transparent images
This setting is to be used to define a background color for semi transparent areas of an alpha transparent when the output format doesn't support alpha transparency This is useful when, from an alpha transparent PNG image, or an image with alpha transparent features if you want to output it as a transparent GIFs for instance, you can set a blending color for transparent areas If you output in JPEG or BMP, this color will be used to fill in the previously transparent areas
The default color white
integer
$image_dst_x
(line 719)
Destination image width
integer
$image_dst_y
(line 727)
Destination image height
string;
$image_flip
(line 1738)
Flips the image vertically or horizontally
Value is either 'h' or 'v', as in horizontal and vertical
Default value is null (no flip)
integer
$image_frame
(line 1883)
Adds a multi-color frame on the outer of the image
Value is an integer. Two values are possible for now:
Note that the dimensions of the picture will be increased by the borders' thickness
Default value is null (no frame)
string
$image_frame_colors
(line 1906)
Sets the colors used to draw a frame
Values is a list of n colors in hexadecimal format. These values can either be in an array, or a space separated string.
The colors are listed in the following order: from the outset of the image to its center
For instance, are valid:
$foo->image_frame_colors = '#FFFFFF #999999 #666666 #000000';
$foo->image_frame_colors = array('#FFFFFF', '#999999', '#666666', '#000000');This setting is used only if image_frame is set
Default value is '#FFFFFF #999999 #666666 #000000'
boolean
$image_is_palette
(line 1302)
Flag set to true when the image is not true color
boolean
$image_is_transparent
(line 1253)
Flag set to true when the image is transparent
This is actually used only for transparent GIFs
integer
$image_max_height
(line 1145)
Set this variable to set a maximum image height, above which the upload will be invalid
Default value is null
long
$image_max_pixels
(line 1155)
Set this variable to set a maximum number of pixels for an image, above which the upload will be invalid
Default value is null
float
$image_max_ratio
(line 1167)
Set this variable to set a maximum image aspect ratio, above which the upload will be invalid
Note that ratio = width / height
Default value is null
integer
$image_max_width
(line 1135)
Set this variable to set a maximum image width, above which the upload will be invalid
Default value is null
integer
$image_min_height
(line 1187)
Set this variable to set a minimum image height, below which the upload will be invalid
Default value is null
long
$image_min_pixels
(line 1197)
Set this variable to set a minimum number of pixels for an image, below which the upload will be invalid
Default value is null
float
$image_min_ratio
(line 1209)
Set this variable to set a minimum image aspect ratio, below which the upload will be invalid
Note that ratio = width / height
Default value is null
integer
$image_min_width
(line 1177)
Set this variable to set a minimum image width, below which the upload will be invalid
Default value is null
string;
$image_overlay_color
(line 1364)
Applies a colored overlay on the image
Value is an hexadecimal color, such as #FFFFFF
To use with image_overlay_percent
Default value is null
integer
$image_overlay_percent
(line 1378)
Sets the percentage for the colored overlay
Value is a percentage, as an integer between 0 and 100
Unless used with image_overlay_color, this setting has no effect
Default value is 50
string
$image_precrop
(line 1792)
Crops an image, before an eventual resizing
See image_crop for valid formats
Default value is null (no cropping)
bool
$image_ratio
(line 1037)
Set this variable to keep the original size ratio to fit within image_x x image_y
Default value is false
mixed
$image_ratio_crop
(line 1053)
Set this variable to keep the original size ratio to fit within image_x x image_y
The image will be resized as to fill the whole space, and excedent will be cropped
Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right) If set as a string, it determines which side of the image is kept while cropping. By default, the part of the image kept is in the center, i.e. it crops equally on both sides
Default value is false
mixed
$image_ratio_fill
(line 1070)
Set this variable to keep the original size ratio to fit within image_x x image_y
The image will be resized to fit entirely in the space, and the rest will be colored. The default color is white, but can be set with image_default_color
Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right) If set as a string, it determines in which side of the space the image is displayed. By default, the image is displayed in the center, i.e. it fills the remaining space equally on both sides
Default value is false
bool
$image_ratio_no_zoom_in
(line 1094)
Set this variable to keep the original size ratio to fit within image_x x image_y, but only if original image is bigger
Default value is false
bool
$image_ratio_no_zoom_out
(line 1105)
Set this variable to keep the original size ratio to fit within image_x x image_y, but only if original image is smaller
Default value is false
mixed
$image_ratio_pixels
(line 1083)
Set this variable to a number of pixels so that image_x and image_y are the best match possible
The image will be resized to have approximatively the number of pixels The aspect ratio wil be conserved
Default value is false
bool
$image_ratio_x
(line 1115)
Set this variable to calculate image_x automatically , using image_y and conserving ratio
Default value is false
bool
$image_ratio_y
(line 1125)
Set this variable to calculate image_y automatically , using image_x and conserving ratio
Default value is false
string;
$image_reflection_color
(line 1711)
Sets the color of the reflection background (deprecated)
Value is an hexadecimal color, such as #FFFFFF
Default value is #FFFFFF
This setting is relevant only if image_reflection_height is set
This setting is now deprecated in favor of image_default_color
mixed;
$image_reflection_height
(line 1681)
Sets the height of the reflection
Value is an integer in pixels, or a string which format can be in pixels or percentage. For instance, values can be : 40, '40', '40px' or '40%'
Default value is null, no reflection
integer
$image_reflection_opacity
(line 1726)
Sets the initial opacity of the reflection
Value is an integer between 0 (no opacity) and 100 (full opacity). The reflection will start from image_reflection_opacity and end up at 0
Default value is 60
This setting is relevant only if image_reflection_height is set
integer
$image_reflection_space
(line 1695)
Sets the space between the source image and its relection
Value is an integer in pixels, which can be negative
Default value is 2
This setting is relevant only if image_reflection_height is set
bool
$image_resize
(line 994)
Set this variable to true to resize the file if it is an image
You will probably want to set image_x and image_y, and maybe one of the ratio variables
Default value is false (no resizing)
string;
$image_rotate
(line 1750)
Rotates the image by increments of 45 degrees
Value is either 90, 180 or 270
Default value is null (no rotation)
integer
$image_src_bits
(line 695)
Source image color depth
long
$image_src_pixels
(line 703)
Number of pixels
string
$image_src_type
(line 711)
Type of image (png, gif, jpg or bmp)
integer
$image_src_x
(line 679)
Source image width
integer
$image_src_y
(line 687)
Source image height
string;
$image_text
(line 1478)
Adds a text label on the image
Value is a string, any text. Text will not word-wrap, although you can use breaklines in your text "\n"
If set, this setting allow the use of all other settings starting with image_text_
Replacement tokens can be used in the string:
gd_version src_name src_name_body src_name_ext src_pathname src_mime src_x src_y src_type src_bits src_pixels src_size src_size_kb src_size_mb src_size_human dst_path dst_name_body dst_pathname dst_name dst_name_ext dst_x dst_y date time host server ipThe tokens must be enclosed in square brackets: [dst_x] will be replaced by the width of the picture
Default value is null
string;
$image_text_alignment
(line 1654)
Sets the text alignment
Value is a string, which can be either 'L', 'C' or 'R'
Default value is 'C'
This setting is relevant only if the text has several lines.
string;
$image_text_background
(line 1526)
Sets the text background color for the text label
Value is an hexadecimal color, such as #FFFFFF
Default value is null (no background)
integer
$image_text_background_percent
(line 1538)
Sets the text background visibility in the text label
Value is a percentage, as an integer between 0 and 100
Default value is 100
string;
$image_text_color
(line 1502)
Sets the text color for the text label
Value is an hexadecimal color, such as #FFFFFF
Default value is #FFFFFF (white)
string;
$image_text_direction
(line 1490)
Sets the text direction for the text label
Value is either 'h' or 'v', as in horizontal and vertical
Default value is h (horizontal)
mixed;
$image_text_font
(line 1551)
Sets the text font in the text label
Value is a an integer between 1 and 5 for GD built-in fonts. 1 is the smallest font, 5 the biggest Value can also be a string, which represents the path to a GDF font. The font will be loaded into GD, and used as a built-in font.
Default value is 5
integer
$image_text_line_spacing
(line 1668)
Sets the text line spacing
Value is an integer, in pixels
Default value is 0
This setting is relevant only if the text has several lines.
integer
$image_text_padding
(line 1612)
Sets the text label padding
Value is in pixels, representing the distance between the text and the label background border
Default value is 0
This setting can be overriden by image_text_padding_x and image_text_padding_y
integer
$image_text_padding_x
(line 1626)
Sets the text label horizontal padding
Value is in pixels, representing the distance between the text and the left and right label background borders
Default value is null
If set, this setting overrides the horizontal part of image_text_padding
integer
$image_text_padding_y
(line 1640)
Sets the text label vertical padding
Value is in pixels, representing the distance between the text and the top and bottom label background borders
Default value is null
If set, his setting overrides the vertical part of image_text_padding
integer
$image_text_percent
(line 1514)
Sets the text visibility in the text label
Value is a percentage, as an integer between 0 and 100
Default value is 100
string;
$image_text_position
(line 1572)
Sets the text label position within the image
Value is one or two out of 'TBLR' (top, bottom, left, right)
The positions are as following:
TL T TR
L R
BL B BRDefault value is null (centered, horizontal and vertical)
Note that is image_text_x and image_text_y are used, this setting has no effect
integer
$image_text_x
(line 1585)
Sets the text label absolute X position within the image
Value is in pixels, representing the distance between the left of the image and the label If a negative value is used, it will represent the distance between the right of the image and the label
Default value is null (so image_text_position is used)
integer
$image_text_y
(line 1598)
Sets the text label absolute Y position within the image
Value is in pixels, representing the distance between the top of the image and the label If a negative value is used, it will represent the distance between the bottom of the image and the label
Default value is null (so image_text_position is used)
integer
$image_threshold
(line 1338)
Applies threshold filter
Value can range between -127 and 127
Default value is null
string;
$image_tint_color
(line 1350)
Applies a tint on the image
Value is an hexadecimal color, such as #FFFFFF
Default value is null
boolean
$image_transparent_color
(line 1263)
Transparent color in a palette
This is actually used only for transparent GIFs
boolean;
$image_unsharp
(line 1410)
Applies an unsharp mask, with alpha transparency support
Beware that this unsharp mask is quite resource-intensive
Default value is FALSE
integer
$image_unsharp_amount
(line 1424)
Sets the unsharp mask amount
Value is an integer between 0 and 500, typically between 50 and 200
Unless used with image_unsharp, this setting has no effect
Default value is 80
integer
$image_unsharp_radius
(line 1438)
Sets the unsharp mask radius
Value is an integer between 0 and 50, typically between 0.5 and 1
Unless used with image_unsharp, this setting has no effect
Default value is 0.5
integer
$image_unsharp_threshold
(line 1452)
Sets the unsharp mask threshold
Value is an integer between 0 and 255, typically between 0 and 5
Unless used with image_unsharp, this setting has no effect
Default value is 1
string;
$image_watermark
(line 1920)
Adds a watermark on the image
Value is a local image filename, relative or absolute. GIF, JPG, BMP and PNG are supported, as well as PNG alpha.
If set, this setting allow the use of all other settings starting with image_watermark_
Default value is null
integer
$image_watermark_no_zoom_in
(line 1982)
Prevents the watermark to be resized up if it is smaller than the image
If the watermark if smaller than the destination image, taking in account the desired watermark position then it will be resized up to fill in the image (minus the image_watermark_x or image_watermark_y values)
If you don't want your watermark to be resized in any way, then set image_watermark_no_zoom_in and image_watermark_no_zoom_out to true If you want your watermark to be resized up or doan to fill in the image better, then set image_watermark_no_zoom_in and image_watermark_no_zoom_out to false
Default value is true (so the watermark will not be resized up, which is the behaviour most people expect)
integer
$image_watermark_no_zoom_out
(line 2000)
Prevents the watermark to be resized down if it is bigger than the image
If the watermark if bigger than the destination image, taking in account the desired watermark position then it will be resized down to fit in the image (minus the image_watermark_x or image_watermark_y values)
If you don't want your watermark to be resized in any way, then set image_watermark_no_zoom_in and image_watermark_no_zoom_out to true If you want your watermark to be resized up or doan to fill in the image better, then set image_watermark_no_zoom_in and image_watermark_no_zoom_out to false
Default value is false (so the watermark may be shrinked to fit in the image)
string;
$image_watermark_position
(line 1938)
Sets the watermarkposition within the image
Value is one or two out of 'TBLR' (top, bottom, left, right)
The positions are as following: TL T TR L R BL B BR
Default value is null (centered, horizontal and vertical)
Note that is image_watermark_x and image_watermark_y are used, this setting has no effect
integer
$image_watermark_x
(line 1951)
Sets the watermark absolute X position within the image
Value is in pixels, representing the distance between the top of the image and the watermark If a negative value is used, it will represent the distance between the bottom of the image and the watermark
Default value is null (so image_watermark_position is used)
integer
$image_watermark_y
(line 1964)
Sets the twatermark absolute Y position within the image
Value is in pixels, representing the distance between the left of the image and the watermark If a negative value is used, it will represent the distance between the right of the image and the watermark
Default value is null (so image_watermark_position is used)
integer
$image_x
(line 1017)
Set this variable to the wanted (or maximum/minimum) width for the processed image, in pixels
Default value is 150
integer
$image_y
(line 1027)
Set this variable to the wanted (or maximum/minimum) height for the processed image, in pixels
Default value is 150
integer
$jpeg_quality
(line 1219)
Quality of JPEG created/converted destination image
Default value is 85
integer
$jpeg_size
(line 1232)
Determines the quality of the JPG image to fit a desired file size
Value is in bytes. The JPG quality will be set between 1 and 100% The calculations are approximations.
Default value is null (no calculations)
array
$language
(line 2046)
Language selected for the translations
By default, the language is english ("en_GB")
string
$log
(line 794)
Holds an HTML formatted log
boolean
$mime_check
(line 848)
Set this variable to false if you don't want to check the MIME against the allowed list
This variable is set to true by default for security reason
boolean
$mime_file
(line 876)
Set this variable to false in the init() function if you don't want to check the MIME with UNIX file() command
This variable is set to true by default for security reason
boolean
$mime_fileinfo
(line 865)
Set this variable to false in the init() function if you don't want to check the MIME with Fileinfo PECL extension. On some systems, Fileinfo is known to be buggy, and you may want to deactivate it in the class code directly.
You can also set it with the path of the magic database file. If set to true, the class will try to read the MAGIC environment variable and if it is empty, will default to '/usr/share/file/magic' If set to an empty string, it will call finfo_open without the path argument
This variable is set to true by default for security reason
boolean
$mime_getimagesize
(line 904)
Set this variable to false in the init() function if you don't want to check the MIME with getimagesize()
The class tries to get a MIME type from getimagesize() If no MIME is returned, it tries to guess the MIME type from the file type
This variable is set to true by default for security reason
boolean
$mime_magic
(line 890)
Set this variable to false in the init() function if you don't want to check the MIME with the magic.mime file
The function mime_content_type() will be deprecated, and this variable will be set to false in a future release
This variable is set to true by default for security reason
boolean
$no_script
(line 912)
Set this variable to false if you don't want to turn dangerous scripts into simple text files
bool
$no_upload_check
(line 768)
Flag stopping PHP upload checks
Indicates whether we instanciated the class with a filename, in which case we will not check on the validity of the PHP *upload*
This flag is automatically set to true when working on a local file
Warning: for uploads, this flag MUST be set to false for security reason
integer
$preserve_transparency
(line 1243)
Preserve transparency when resizing or converting an image (deprecated)
Default value is automatically set to true for transparent GIFs This setting is now deprecated
bool
$processed
(line 778)
Flag set after calling a process
Indicates if the processing, and copy of the resulting file went OK
array
$translation
(line 2036)
Array of translated error messages
By default, the language is english (en_GB) Translations can be in separate files, in a lang/ subdirectory
bool
$uploaded
(line 753)
Flag set after instanciating the class
Indicates if the file has been uploaded properly
string
$version
(line 559)
Class version
Deletes the uploaded file from its temporary location
When PHP uploads a file, it stores it in a temporary location. When you process the file, you actually copy the resulting file to the given location, it doesn't alter the original file. Once you have processed the file as many times as you wanted, you can delete the uploaded file. If there is open_basedir restrictions, the uploaded file is in fact a temporary file
You might want not to use this function if you work on local files, as it will delete the source file
Returns the version of GD
Saves a BMP image
This function has been published on the PHP website, and can be used freely
Opens a BMP image
This function has been written by DHKold, and is used with permission of the author
Actually uploads the file, and act on it according to the set processing class variables
This function copies the uploaded file to the given location, eventually performing actions on it. Typically, you can call process several times for the same file, for instance to create a resized image and a thumbnail of the same file. The original uploaded file remains intact in its temporary location, so you can use process several times. You will be able to delete the uploaded file with clean when you have finished all your process calls.
According to the processing class variables set in the calling file, the file can be renamed, and if it is an image, can be resized or converted.
When the processing is completed, and the file copied to its new location, the processing class variables will be reset to their default value. This allows you to set new properties, and perform another process on the same uploaded file
If the function is called with a null or empty argument, then it will return the content of the picture
It will set processed (and error is an error occurred)