break; } $r = array('filesize' => filesize($tmpfile), 'width' => $des_width, 'height' => $des_height);; copy($tmpfile, $destfile); is_file($tmpfile) && unlink($tmpfile); imagedestroy($img_dst); return $r; } /** * 图片裁切 * * @param string $sourcefile 原图片路径(绝对路径/abc.jpg) * @param string $destfile 裁切后生成新名称(绝对路径/rename.jpg) * @param int $clipx 被裁切图片的X坐标 * @param int $clipy 被裁切图片的Y坐标 * @param int $clipwidth 被裁区域的宽度 * @param int $clipheight 被裁区域的高度 * image_clip('xxx/x.jpg', 'xxx/newx.jpg', 10, 40, 150, 150) */ function well_image_clip($sourcefile, $destfile, $clipx, $clipy, $clipwidth, $clipheight, $getimgsize = '') { global $conf; empty($getimgsize) AND $getimgsize = getimagesize($sourcefile); if (empty($getimgsize)) { return 0; } else { $imgwidth = $getimgsize[0]; $imgheight = $getimgsize[1]; if (0 == $imgwidth || 0 == $imgheight) { return 0; } } if (!function_exists('imagecreatefromjpeg')) { copy($sourcefile, $destfile); return filesize($destfile); } switch ($getimgsize[2]) { case 1 : $imgcolor = imagecreatefromgif($sourcefile); break; case 2 : $imgcolor = imagecreatefromjpeg($sourcefile); break; case 3 : $imgcolor = imagecreatefrompng($sourcefile); break; case 15: // WBMP $imgcolor = imagecreatefromwbmp($sourcefile); break; case 18: // WEBP $imgcolor = imagecreatefromwebp($sourcefile); break; } if (!$imgcolor) return 0; $img_dst = imagecreatetruecolor($clipwidth, $clipheight); imagefill($img_dst, 0, 0, 0xFFFFFF); imagecopyresampled($img_dst, $imgcolor, 0, 0, $clipx, $clipy, $imgwidth, $imgheight, $imgwidth, $imgheight); $tmppath = isset($conf['tmp_path']) ? $conf['tmp_path'] : ini_get('upload_tmp_dir') . '/'; '/' == $tmppath AND $tmppath = './tmp/'; $tmpfile = $tmppath . md5($destfile) . '.tmp'; imagejpeg($img_dst, $tmpfile, 75); $n = filesize($tmpfile); copy($tmpfile, $destfile); is_file($tmpfile) && unlink($tmpfile); return $n; } function well_image_ext($filename) { return strtolower(substr(strrchr($filename, '.'), 1)); } ?>策略

设计模式 - 策略模式(Strategy)

Strategy模式定义一系列的算法,把它们一个个封装起来, 并且使它们可相互替换。本模式使得算法可独立于使用它的客户而变化。 类图:案例: 不同的员工薪资计算不同。 没有实现Strate

7月前800

设计模式之策略设计模式(Strategy)

定义:策略模式定义了一系列的算法,并将每一个算法封装起来,而且使他们可以相互替换,让算法独立于使用它的客户而独立变化。这个模式涉及到三个角色&#

7月前1020

Kafka分区分配策略(Partition Assignment Strategy)

问题 用过 Kafka 的同学用过都知道,每个 Topic 一般会有很多个 partitions。为了使得我们能够及时消费消息,我们也可能会启动多个 Consumer 去消费&#xff0

7月前1000

量化金融分析AQF(9):动量策略-Momentum Strategy

目录 一、动量策略描述 1.1 策略思想 1.2 过去收益好的定义 二、动量策略代码实现 1. 数据准备 2. 策略开发思路 3. 策略可视化 4. 策略优化之思路——参数优化和穷举 5. 参数寻优——使用离散Return

7月前670

Java设计模式—策略模式(Strategy)

模式动机完成一项任务,往往可以有多种不同的方式,每一种方式称为一个策略,我们可以根据环境或者条件的不同选择不同的策略来完成该项任务。在软件开发中也常常遇到类似的情况&

7月前1180

Strategy(策略)

Strategy(策略) 行为型 对象 1 Intent_意图2 定义了算法族,分别封装起来,让它们之间可以互相替换,此模式让

7月前860

设计模式-策略模式 Strategy

策略模式1) 原理和实现1、策略的定义2、策略的创建3、策略的使用该模式最常见的应用场景是,利用它来避免冗长的 if-else 或 switch 分支判断。不过,它的作用还不止如此。它也可以像模板

7月前920

设计模式-策略模式(Strategy Pattern)

推荐:Java设计模式汇总 策略模式 定义 定义了一组算法,将每个算法都封装起来,并且使它们之间可以互换,且算法的变化不会影响使用算法的客户。它通过

7月前880

Matlab策略模式(Strategy)

策略模式的意图是定义一系列算法,把它们一个一个封装起来,并且使它们可以互相替换。通常每个策略算法不可抽象再分。本人仿照https:www.runoobdesign-patternstrat

7月前800