use of org.olat.core.commons.services.image.Crop in project OpenOLAT by OpenOLAT.
the class FileElementImpl method moveUploadFileTo.
@Override
public VFSLeaf moveUploadFileTo(VFSContainer destinationContainer, boolean crop) {
VFSLeaf targetLeaf = null;
if (tempUploadFile != null && tempUploadFile.exists()) {
// Check if such a file does already exist, if yes rename new file
VFSItem existsChild = destinationContainer.resolve(uploadFilename);
if (existsChild != null) {
// Use standard rename policy
uploadFilename = VFSManager.rename(destinationContainer, uploadFilename);
}
// Create target leaf file now and delete original temp file
if (destinationContainer instanceof LocalFolderImpl) {
// Optimize for local files (don't copy, move instead)
LocalFolderImpl folderContainer = (LocalFolderImpl) destinationContainer;
File destinationDir = folderContainer.getBasefile();
File targetFile = new File(destinationDir, uploadFilename);
Crop cropSelection = previewEl == null ? null : previewEl.getCropSelection();
if (crop && cropSelection != null) {
CoreSpringFactory.getImpl(ImageService.class).cropImage(tempUploadFile, targetFile, cropSelection);
targetLeaf = (VFSLeaf) destinationContainer.resolve(targetFile.getName());
} else if (FileUtils.copyFileToFile(tempUploadFile, targetFile, true)) {
targetLeaf = (VFSLeaf) destinationContainer.resolve(targetFile.getName());
} else {
log.error("Error after copying content from temp file, cannot copy file::" + (tempUploadFile == null ? "NULL" : tempUploadFile) + " - " + (targetFile == null ? "NULL" : targetFile), null);
}
if (targetLeaf == null) {
log.error("Error after copying content from temp file, cannot resolve copied file::" + (tempUploadFile == null ? "NULL" : tempUploadFile) + " - " + (targetFile == null ? "NULL" : targetFile), null);
}
} else {
// Copy stream in case the destination is a non-local container
VFSLeaf leaf = destinationContainer.createChildLeaf(uploadFilename);
boolean success = false;
try {
success = VFSManager.copyContent(new FileInputStream(tempUploadFile), leaf);
} catch (FileNotFoundException e) {
log.error("Error while copying content from temp file::" + (tempUploadFile == null ? "NULL" : tempUploadFile.getAbsolutePath()), e);
}
if (success) {
// Delete original temp file after copy to simulate move
// behavior
tempUploadFile.delete();
targetLeaf = leaf;
}
}
} else if (log.isDebug()) {
log.debug("Error while copying content from temp file, no temp file::" + (tempUploadFile == null ? "NULL" : tempUploadFile.getAbsolutePath()));
}
return targetLeaf;
}
use of org.olat.core.commons.services.image.Crop in project OpenOLAT by OpenOLAT.
the class ImageFormItem method getCropSelection.
public Crop getCropSelection() {
if (cropSelection == null)
return null;
float scalingFactor = imageComponent.getScalingFactor();
if (scalingFactor <= 0f || Float.isNaN(scalingFactor))
return null;
int x = cropSelection.getX();
int y = cropSelection.getY();
int width = cropSelection.getWidth();
int height = cropSelection.getHeight();
// log.info("At: " + x + " : " + y + " size: " + width + " x" + height);
Crop realCropSelection = new Crop();
realCropSelection.setWidth(width);
realCropSelection.setHeight(height);
realCropSelection.setX(x);
realCropSelection.setY(y);
return realCropSelection;
}
use of org.olat.core.commons.services.image.Crop in project openolat by klemens.
the class ImageFormItem method getCropSelection.
public Crop getCropSelection() {
if (cropSelection == null)
return null;
float scalingFactor = imageComponent.getScalingFactor();
if (scalingFactor <= 0f || Float.isNaN(scalingFactor))
return null;
int x = cropSelection.getX();
int y = cropSelection.getY();
int width = cropSelection.getWidth();
int height = cropSelection.getHeight();
// log.info("At: " + x + " : " + y + " size: " + width + " x" + height);
Crop realCropSelection = new Crop();
realCropSelection.setWidth(width);
realCropSelection.setHeight(height);
realCropSelection.setX(x);
realCropSelection.setY(y);
return realCropSelection;
}
Aggregations