本文标题:《「水坑」关于 Z-BlogPHP 1.7 缩略图的一些记录》。
镜像链接:https://www.wdssmq.com/post/20210224481.html
Z-BlogPHP 1.7 将会提供一个Thumb
基础类,本身只实现从「原图」到「缩略图」的转换和保存,简单说就是自动帮你变小。
生成路径为zb_users/cache/thumbs/
。
Z-BlogPHP 1.7 将会提供一个Thumb
基础类,本身只实现从「原图」到「缩略图」的转换和保存,简单说就是自动帮你变小。
生成路径为zb_users/cache/thumbs/
。
主题内的使用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| function ActivePlugin_acgME() { Add_Filter_Plugin('Filter_Plugin_ViewList_Template', 'acgME_Main'); Add_Filter_Plugin('Filter_Plugin_Post_Thumbs', 'acgME_Thumbs'); Add_Filter_Plugin('Filter_Plugin_Zbp_BuildTemplate', 'acgME_BuidTemp'); } function acgME_Main(&$template) { global $zbp; if ($articles = $template->GetTags('articles')) { foreach ($articles as $article) { acgME_SetIMG($article); } } }
function acgME_Thumbs($article, &$all_images, $width, $height, $count, $clip) { $rndNum = $article->ID % 19 + 1; $rndImg = acgME_Path("v-noimg", "host") . $rndNum . ".jpg"; $all_images[] = $rndImg; Thumb::changeDefaultImg($rndImg); }
function acgME_SetIMG(&$article) { if (!isset($article->Img_640x360)) { $article->Img_640x360 = $article->Thumbs(640, 360, 1, false)[0]; } }
function acgME_BuidTemp(&$templates) { global $zbp; $templates['n-slide'] = ""; if (!$zbp->template->HasTemplate("m-slide")) { return; } $uFile = acgME_Path("u-slide"); if (!is_file($uFile)) { return; } $slides = json_decode(file_get_contents($uFile)); foreach ($slides as $key => &$item) { $item->Img_142x80 = Thumb::Thumbs([$item->Img], 142, 80, 1, false)[0]; $item->Img_647x404 = Thumb::Thumbs([$item->Img], 647, 404, 1, false)[0]; } $zbp->template->SetTags('slides', $slides); $templates['n-slide'] = $zbp->template->Output("m-slide"); $script = $zbp->host . 'zb_users/theme/acgME/script/swiper-3.4.2.jquery.min.js'; $templates['n-slide'] .= '{php}$footer .= \'<script src="' . script .'"></script>\'{/php}'; $script = $zbp->host . 'zb_users/theme/acgME/script/swiper-act.js'; $templates['n-slide'] .= '{php}$footer .= \'<script src="' . $script . '"></script>\'{/php}'; }
|
模板内调用:
1
| <div class="post-img"><img src="{$article.Img_640x360}" alt="{$article.Title}"></div>
|
关于图片裁切部分的代码笔记
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| public function handle() { if ($this->shouldClip) { $src_scale = ($this->srcWidth / $this->srcHeight); $dst_scale = ($this->dstWidth / $this->dstHeight);
$h_scale = ($this->srcHeight / $this->dstHeight); $w_scale = ($this->srcWidth / $this->dstWidth);
$w_des = ($this->dstWidth * $h_scale); $h_des = ($this->dstHeight * $w_scale);
if ($src_scale >= $dst_scale) { $dst_widthx = (($this->srcWidth - $w_des) / 2); $this->clip($dst_widthx, 0, $w_des, $this->srcHeight); $this->zoom($this->dstWidth, $this->dstHeight); } else { $dst_heighty = (($this->srcHeight - $h_des) / 2); $this->clip(0, $dst_heighty, $this->srcWidth, $h_des); $this->zoom($this->dstWidth, $this->dstHeight); } } else { $this->zoom($this->dstWidth); } $this->save(); imagedestroy($this->srcRes); }
|
其他
「备忘」访止别人用 iframe 调用你的页面_电脑网络_沉冰浮水:
https://www.wdssmq.com/post/20160730633.html