The processing method is:
1. When the original image of the width or height of any smaller than the specified size, only to carry out, such as abbreviated processing,
2. When the original image of the width and height are larger than the specified size, the first to be compared to the abbreviated processing, and then calculate the center position for cutting
<?php
/*
* $o _photo Original path
* $d _photo image path after processing
* $width definition width
* $height High Definition
* Call Method Cutphoto ("Test.jpg", "temp.jpg", 256,146);
*/
function Cutphoto ($o _photo, $d _photo, $width, $height) {
$temp _img = imagecreatefromjpeg ($o _photo);
$o _width = imagesx ($temp _img); Get the original image wide
$o _height = Imagesy ($temp _img); Get high
Judgment Processing method
if ($width > $o _width | | $height > $o _height) {//Huantuquan or higher than the specified size, compress
}else{//Huantuquan and height are larger than the specified size, after compression cut
if ($o _height* $width/$o _width> $height) {//Make sure the width is the same as the rule, if the height is larger than the specified, OK
$newwidth = $width;
$newheight = $o _height* $width/$o _width;
$x = 0;
$y = ($newheight-$height)/2;
}else{//Otherwise determine the height is the same as the specified, Width adaptive
$newwidth = $o _width* $height/$o _height;
$newheight = $height;
$x = ($newwidth-$width)/2;
$y = 0;
}
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.