mirror of https://github.com/halo-dev/halo
Refactor generateThumbnail method.
parent
f375c28733
commit
d41d3d8517
|
@ -43,13 +43,12 @@ bootJar {
|
|||
|
||||
ext {
|
||||
ohMyEmailVersion = '0.0.4'
|
||||
hutoolVersion = '4.5.0'
|
||||
hutoolVersion = '4.6.3'
|
||||
upyunSdkVersion = '4.0.1'
|
||||
qiniuSdkVersion = '7.2.18'
|
||||
aliyunSdkVersion = '3.4.2'
|
||||
baiduSdkVersion = '0.10.36'
|
||||
qcloudSdkVersion = '5.5.7'
|
||||
thumbnailatorVersion = '0.4.8'
|
||||
swaggerVersion = '2.9.2'
|
||||
commonsLangVersion = '3.8.1'
|
||||
httpclientVersion = '4.5.7'
|
||||
|
@ -74,7 +73,6 @@ dependencies {
|
|||
implementation "com.aliyun.oss:aliyun-sdk-oss:$aliyunSdkVersion"
|
||||
implementation "com.baidubce:bce-java-sdk:$baiduSdkVersion"
|
||||
implementation "com.qcloud:cos_api:$qcloudSdkVersion"
|
||||
implementation "net.coobird:thumbnailator:$thumbnailatorVersion"
|
||||
implementation "io.springfox:springfox-swagger2:$swaggerVersion"
|
||||
implementation "io.springfox:springfox-swagger-ui:$swaggerVersion"
|
||||
implementation "org.apache.commons:commons-lang3:$commonsLangVersion"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#Mon Sep 09 12:27:59 CST 2019
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package run.halo.app.handler.file;
|
||||
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.coobird.thumbnailator.Thumbnails;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -31,7 +31,8 @@ import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
|||
* Local file handler.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/27/19
|
||||
* @author ryanwang
|
||||
* @date 2019-03-27
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
|
@ -47,11 +48,13 @@ public class LocalFileHandler implements FileHandler {
|
|||
/**
|
||||
* Thumbnail width.
|
||||
*/
|
||||
@Deprecated
|
||||
private final static int THUMB_WIDTH = 256;
|
||||
|
||||
/**
|
||||
* Thumbnail height.
|
||||
*/
|
||||
@Deprecated
|
||||
private final static int THUMB_HEIGHT = 256;
|
||||
|
||||
private final OptionService optionService;
|
||||
|
@ -135,8 +138,11 @@ public class LocalFileHandler implements FileHandler {
|
|||
uploadResult.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
|
||||
uploadResult.setSize(file.getSize());
|
||||
|
||||
// TODO refactor this: if image is svg ext. extension
|
||||
boolean isSvg = "svg".equals(extension);
|
||||
|
||||
// Check file type
|
||||
if (FileHandler.isImageType(uploadResult.getMediaType())) {
|
||||
if (FileHandler.isImageType(uploadResult.getMediaType()) && !isSvg) {
|
||||
// Upload a thumbnail
|
||||
String thumbnailBasename = basename + THUMBNAIL_SUFFIX;
|
||||
String thumbnailSubFilePath = subDir + thumbnailBasename + '.' + extension;
|
||||
|
@ -154,9 +160,10 @@ public class LocalFileHandler implements FileHandler {
|
|||
// Set width and height
|
||||
uploadResult.setWidth(image.getWidth());
|
||||
uploadResult.setHeight(image.getHeight());
|
||||
|
||||
// Set thumb path
|
||||
uploadResult.setThumbPath(thumbnailSubFilePath);
|
||||
} else {
|
||||
uploadResult.setThumbPath(subFilePath);
|
||||
}
|
||||
|
||||
return uploadResult;
|
||||
|
@ -220,7 +227,7 @@ public class LocalFileHandler implements FileHandler {
|
|||
log.info("Generating thumbnail: [{}] for image: [{}]", thumbPath.getFileName(), imagePath.getFileName());
|
||||
|
||||
// Convert to thumbnail and copy the thumbnail
|
||||
Thumbnails.of(imagePath.toFile()).size(THUMB_WIDTH, THUMB_HEIGHT).keepAspectRatio(true).toFile(thumbPath.toFile());
|
||||
ImgUtil.scale(imagePath.toFile(), thumbPath.toFile(), 0.1f);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ import java.util.Date;
|
|||
* @author johnniang
|
||||
* @date 3/20/19
|
||||
*/
|
||||
@MappedSuperclass
|
||||
@Data
|
||||
@ToString
|
||||
@MappedSuperclass
|
||||
@EqualsAndHashCode
|
||||
public class BaseEntity {
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public class BasePost extends BaseEntity {
|
|||
/**
|
||||
* Post url.
|
||||
*/
|
||||
@Column(name = "url", columnDefinition = "varchar(255) not null")
|
||||
@Column(name = "url", columnDefinition = "varchar(255) not null", unique = true)
|
||||
private String url;
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,7 +31,7 @@ public class Category extends BaseEntity {
|
|||
/**
|
||||
* Category slug name.
|
||||
*/
|
||||
@Column(name = "slug_name", columnDefinition = "varchar(50) not null")
|
||||
@Column(name = "slug_name", columnDefinition = "varchar(50) not null", unique = true)
|
||||
private String slugName;
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,7 +33,7 @@ public class Tag extends BaseEntity {
|
|||
/**
|
||||
* Tag slug name.
|
||||
*/
|
||||
@Column(name = "slug_name", columnDefinition = "varchar(255) not null")
|
||||
@Column(name = "slug_name", columnDefinition = "varchar(255) not null", unique = true)
|
||||
private String slugName;
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue