Detailed explanation of the solution to the distortion and blurring of DedeCMS thumbnails

黄舟
Release: 2023-03-07 08:44:01
Original
1514 people have browsed it

This article mainly introduces DreamWeaver DedeCMSThumbnail The perfect solution to distortion and blur , since dede only generates one size thumbnail by default, which cannot meet the needs of most websites, this article gives an ultimate and perfect solution. Friends in need can refer to it

Since dede only generates one thumbnail by default Thumbnails of different sizes are often inconsistent in size and proportion in different pages of a website, which results in unclear and distorted thumbnails. The method provided below perfectly solves this problem.

dedecms template download address: www.php.cn/xiazai/code/dedecms

Instructions for use:

1. To get a clear thumbnail, it must be large enough Picture and crop it accurately, and the following method is to crop it based on the thumbnail (because some websites of the original picture have watermarks), so you must ensure that the original thumbnail is large enough, so you need to set it up: System- Attachment settings, set the default width and height of thumbnails to be greater than or equal to the maximum size of all thumbnails called in your entire site. Please also cut it to a large enough size for manual trimming (no need for manual trimming)

2. Open include/extend.func.php (Note: This file is prepared for secondary development and used for functional method expansion)

Add the following code before the last ?>

The code is as follows:

function thumb($imgurl, $
width
, $
height
, $bg = true)
 {
 global $cfg_
main
site,$cfg_multi_site;
 $thumb = eregi("http://",$imgurl)?
str_replace
($cfg_mainsite,'',$imgurl):$imgurl;
 
list
($thumbname,$extname) = 
explode
('.',$thumb);
 $
new
thumb = $thumbname.'_'.$width.'_'.$height.'.'.$extname;
if
(!$thumbname || !$extname || !
file_exists
(DEDEROOT.$thumb)) 
return
 $imgurl;
 if(!file_exists(DEDEROOT.$newthumb))
{
 
include_once
 DEDEINC.'/image.func.php';
 if($bg==true)
 {
 ImageResizeNew(DEDEROOT.$thumb, $width, $height, DEDEROOT.$newthumb);
 }
 
else
 {
 ImageResize(DEDEROOT.$thumb, $width, $height, DEDEROOT.$newthumb);
 }
 }
 return $cfg_multi_site=='Y'?$cfg_mainsite.$newthumb:$newthumb;
 }
Copy after login

Calling method:

Tag:

 [field:picname function='thumb(@me,$width,$height,$bg)'/]
Copy after login

Parameter description:

$width: thumbnail width (Integer )
$height: Thumbnail height (integer)
$bg: Whether to fill with blanks, automatically filled by default, background fill color is in the system-attachment settings (true/false)

Example:

Call a thumbnail with a length and width of 100 pixels:

[field:picname function='thumb(@me,100,100)'/]
Copy after login

Keep the original proportion and do not automatically fill (not recommended):

[field:picname function='thumb(@me,100,100,false)'/]
Copy after login

The above is the detailed content of Detailed explanation of the solution to the distortion and blurring of DedeCMS thumbnails. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!