PHP按最大宽高缩略图片函数代码
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Libérer: 2016-07-25 08:51:08
original
1076 Les gens l'ont consulté
很简单的按照最大宽高来缩略图片的代码,方便新手和懒得自己写的人
- function thumb($imagefile, $maxwidth, $maxheight) {
- $dim = getimagesize($imagefile);
- $width = $dim[0]; //原图宽度
- $height = $dim[1]; //原图高度
- $original = imagecreatefromjpeg($imagefile);
-
- $thcrown = $maxwidth/$maxheight; //缩略图最大宽度与最大高度比
- $crown = $width/$height; //原图宽高比
- if($crown/$thcrown >= 1){
- $thumbWidth = $maxwidth;
- $thumbHeight = $maxwidth/$crown;
- } else {
- $thumbHeight = $maxheight;
- $thumbWidth = $maxheight*$crown;
- }
-
- $thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
- imagecopyresampled($thumb, $original, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height);
- return $thumb;
- }
复制代码
|
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers articles par auteur
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11