PHP按最大宽高缩略图片函数代码
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-07-25 08:51:08
asal
1086 orang telah melayarinya
很简单的按照最大宽高来缩略图片的代码,方便新手和懒得自己写的人
- 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;
- }
复制代码
|
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
-
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
Isu terkini
-
2025-03-21 13:39:34
-
2025-03-21 13:38:34
-
2025-03-21 13:37:19
-
2025-03-21 13:35:24
-
2025-03-21 13:34:32
Topik-topik yang berkaitan
Lagi>