What are the PHP forms and thumbnail processing classes?

Source: Internet
Author: User

<?php
Encapsulates a form validation class
Chinese verification, email verification, phone number, mobile phone, QQ, ID card, (composed of letters, numbers, underscores, cannot start with a number)
Header (' Content-type:text/html;charset=utf-8 ');
Class form{
/*
Methods of Chinese verification
Parameters: $str, $num 1, $num 2
Return value: The number of matches that matched successfully returned
*/
Public Function Checkchina ($STR, $num 1, $num 2 = ") {
Regular
$reg = '/^[\x{4e00}-\x{9fa5}]{'. $num 1. ', '. $num 2. '} '. ' $/u ';
Return Preg_match ($reg, $STR);
}
/*
Mailbox Verification
Parameters: $email
Return value: The number of matches that matched successfully returned
*/
Public Function Checkemail ($email) {
Regular
$reg = '/^\[email protected]\w+[.] com|cn|net$/';
Return Preg_match ($reg, $email);
}
/*
Verify ID
Parameter $card
Return value: The number of matches that matched successfully returned
*/
Public Function Checkcard ($card) {
Regular
$reg = '/^ (\d{18}|\d{17}x) $/';
Return Preg_match ($reg, $card);
}
/*
Required input content consists of numbers, letters, underscores, cannot start with a number, there is a limit to the number of digits
Parameters: $str, $num 1, $num 2
Return value: The number of matches that matched successfully returned
*/
Public Function Checkstr ($STR, $num 1, $num 2) {
Regular
$reg = '/^[a-za-z_]\w{'. ( $num 1-1). ', '. ($num 2-1). '} $/';
Return Preg_match ($reg, $STR);
}
}

<?php
Picture processing Tool Class
Class image{
Property
Private $thumb _width; The width of the thumbnail image
Private $thumb _height;
Error properties
Public $thumb _error;
Construction method
Public function __construct ($width = 0, $height = 0) {
$this->thumb_width = ($width = = 0)? $GLOBALS [' config '] [' admin_goods_thumb '] [' width ']: $width;
$this->thumb_height = ($height = = 0)? $GLOBALS [' config '] [' admin_goods_thumb '] [' height ']: $height;
}
/*
* Make thumbnail images
* @param1 string $src, original path,/uploads/20150122101010abcdef.gif
* @param2 string $path, thumbnail save path/uploads/thumb_20150122101010abcdef.gif
* @return The name of the thumbnail image
*/
Public Function Makethumb ($SRC, $path) {
Determine if the original image exists
if (!file_exists ($SRC)) {
$this->thumb_error = ' artwork does not exist! ‘;
return false;
}
Open Original source
Get the suffix you can use
$ext = $this->getfunctionname ($SRC); Gif
Piece of patchwork function name
$open = ' Imagecreatefrom '. $ext; Imagecreatefromgif
$save = ' image '. $ext; Imagegif
If not clear; Echo $open, $save; exit;
Variable function Open Original source
$src _img = $open ($SRC); Open a picture resource with a mutable function
Imagecreatefromgif ($SRC)
Thumbnail resources
$DST _img = Imagecreatetruecolor ($this->thumb_width, $this->thumb_height);
White background filled with color
$DST _bg_color = imagecolorallocate ($dst _img,255,255,255);
Imagefill ($dst _img,0,0, $dst _bg_color);
Width-to-height ratio determination of wide height
$DST _size = $this->thumb_width/$this->thumb_height;
Get the original data
$file _info = getimagesize ($SRC);
$src _size = $file _info[0]/$file _info[1];
Find the thumbnail width and height
if ($src _size > $dst _size) {
The original aspect ratio is greater than the thumbnail image
$width = $this->thumb_width;
$height = Round ($width/$src _size);
}else{
$height = $this->thumb_height;
$width = Round ($height * $src _size);
}
Find the starting position of the thumbnail image
$DST _x = round ($this->thumb_width-$width)/2;
$DST _y = round ($this->thumb_height-$height)/2;
Make thumbnail images
if (imagecopyresampled ($dst _img, $src _img, $dst _x, $dst _y,0,0, $width, $height, $file _info[0], $file _info[1])) {
Sample successful: Save, save the file to the corresponding path
$thumb _name = ' thumb_ '. BaseName ($SRC);
$save ($dst _img, $path. ‘/‘ . $thumb _name);
Saved successfully
return $thumb _name;
}else{
Sampling failed
$this->thumb_error = ' thumbnail sampling failed! ‘;
return false;
}
}
/*
* Get the name of the function to be called by the file
* @param1 string $file, file name
* @return The function string obtained by the file suffix name
*/
Private Function Getfunctionname ($file) {
Get the suffix of the file
$file _info = PathInfo ($file);
$ext = $file _info[' extension '); Suffix: gif,png,jpg,jpeg,pjpeg
Imagecreatefromgif,imagecreatefromjpeg,imagecreatefrompng
Defines an array of Save function names
$func = Array (
' gif ' = ' gif ',
' png ' = ' png ',
' jpg ' = ' jpeg ',
' JPEG ' = ' jpeg ',
' Pjpeg ' = ' jpeg '
);
return value
return $func [$ext];
}
}

What are the PHP forms and thumbnail processing classes?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.