Home>Article>Backend Development> Detailed explanation of the solution to the distortion and blurring of DedeCMS thumbnails

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

Susan Sarandon
Susan Sarandon Original
2017-04-01 09:41:16 1459browse

This article mainly introduces DreamWeaver DedeCMSThumbnailThe 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: m.sbmmt.com/xiazai/code/dedecms

Instructions for use:

1. To get a clear thumbnail, it must be large enoughPictureand 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. Openinclude/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; }

Calling method:

Tag:

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

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)'/]

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

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

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!

Statement:
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