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