Search in sources :

Example 6 with Crop

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;
}
Also used : Crop(org.olat.core.commons.services.image.Crop) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FileNotFoundException(java.io.FileNotFoundException) VFSItem(org.olat.core.util.vfs.VFSItem) File(java.io.File) ImageService(org.olat.core.commons.services.image.ImageService) FileInputStream(java.io.FileInputStream) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 7 with Crop

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;
}
Also used : Crop(org.olat.core.commons.services.image.Crop)

Example 8 with Crop

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;
}
Also used : Crop(org.olat.core.commons.services.image.Crop)

Aggregations

Crop (org.olat.core.commons.services.image.Crop)8 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 ImageService (org.olat.core.commons.services.image.ImageService)2 Size (org.olat.core.commons.services.image.Size)2 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)2 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VideoMeta (org.olat.modules.video.VideoMeta)2