Home > CMS Tutorial > DEDECMS > body text

What should I do if the thumbnail is distorted when calling DreamWeaver CMS?

藏色散人
Release: 2023-02-22 17:01:24
Original
1722 people have browsed it

Solution to the distortion of thumbnails called by DreamWeaver cms: 1. In "System-Attachment Settings", set the default width and height of the thumbnails to be greater than or equal to the maximum size of all called thumbnails in the entire site; 2. Open the "/include/extend.func.php" file and add the code as "function thumb($imgurl, $width, $height, $bg = true){...}".

What should I do if the thumbnail is distorted when calling DreamWeaver CMS?

The operating environment of this tutorial: Windows 10 system, DedeCMS version 5.7, Dell G3 computer.

What should I do if the thumbnail is distorted when calling DreamWeaver cms?

Solution to dede thumbnail distortion and blurring

Since dedecms only generates one size thumbnail by default, the thumbnails required in different pages of a website are often The thumbnails are inconsistent in size and proportion, which results in unclear and distorted thumbnails, which cannot meet the needs of most websites. This article gives an ultimate solution

Modification method:

1. To obtain clear thumbnails, you need to have a large enough image and crop it accurately. The following method is to crop based on the thumbnail (because some websites in the original image have watermarks), so you must Make sure that the original thumbnail is large enough, so you need to make some settings: System - Attachment Settings, set the default width and default height of the thumbnail to be greater than or equal to the maximum size of all the thumbnails called in your entire site. Please also cut it to be large enough for manual cutting. (No need to cut it by hand)

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

Add the following code before the last ?>:

function thumb($imgurl, $width, $height, $bg = true)
{
global $cfg_mainsite,$cfg_multi_site;
$thumb = eregi("http://",$imgurl)?str_replace($cfg_mainsite,'',$imgurl):$imgurl;
list($thumbname,$extname) = explode('.',$thumb);
$newthumb = $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:

[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-accessory settings (true/false)

Example:

Call a thumbnail with a length and width of 100 pixels: [field:picname function='thumb(@me,100,100)'/]

Retain the original proportion , no automatic filling (not recommended): [field:picname function='thumb(@me,100,100,false)'/]

Recommended learning: dedecms tutorial

The above is the detailed content of What should I do if the thumbnail is distorted when calling DreamWeaver CMS?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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!