Exemple #1
0
 /**
  * @dataProvider convertDataProvider
  */
 public function testConvert($mimeType)
 {
     $img = new \OC_Image(OC::$SERVERROOT . '/tests/data/testimage.png');
     $tempFile = tempnam(sys_get_temp_dir(), 'img-test');
     $img->save($tempFile, $mimeType);
     $actualMimeType = \OC_Image::getMimeTypeForFile($tempFile);
     $this->assertEquals($mimeType, $actualMimeType);
 }
 public static function getThumbnail($image_name, $owner = null)
 {
     if (!$owner) {
         $owner = OCP\USER::getUser();
     }
     $save_dir = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery/';
     $save_dir .= dirname($image_name) . '/';
     $image_path = $image_name;
     $thumb_file = $save_dir . basename($image_name);
     if (!is_dir($save_dir)) {
         mkdir($save_dir, 0777, true);
     }
     if (file_exists($thumb_file)) {
         $image = new OC_Image($thumb_file);
     } else {
         $image_path = OC_Filesystem::getLocalFile($image_path);
         if (!file_exists($image_path)) {
             return null;
         }
         $image = new OC_Image($image_path);
         if ($image->valid()) {
             $image->centerCrop(200);
             $image->fixOrientation();
             $image->save($thumb_file);
         }
     }
     if ($image->valid()) {
         return $image;
     } else {
         $image->destroy();
     }
     return null;
 }
}
if (!isset($_GET['path'])) {
    bailOut(OC_Contacts_App::$l10n->t('No photo path was submitted.'));
}
$localpath = OC_Filesystem::getLocalFile($_GET['path']);
$tmpfname = tempnam(get_temp_dir(), "occOrig");
if (!file_exists($localpath)) {
    bailOut(OC_Contacts_App::$l10n->t('File doesn\'t exist:') . $localpath);
}
file_put_contents($tmpfname, file_get_contents($localpath));
$image = new OC_Image();
if (!$image) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if (!$image->loadFromFile($tmpfname)) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if ($image->width() > 400 || $image->height() > 400) {
    $image->resize(400);
    // Prettier resizing than with browser and saves bandwidth.
}
if (!$image->fixOrientation()) {
    // No fatal error so we don't bail out.
    debug('Couldn\'t save correct image orientation: ' . $tmpfname);
}
if ($image->save($tmpfname)) {
    OCP\JSON::success(array('data' => array('id' => $_GET['id'], 'tmp' => $tmpfname)));
    exit;
} else {
    bailOut('Couldn\'t save temporary image: ' . $tmpfname);
}
Exemple #4
0
 public static function getViewImage($image_name, $owner = null)
 {
     if (!$owner) {
         $owner = OCP\USER::getUser();
     }
     $view_file = OC_Filesystem::getLocalFile($image_name);
     if (!is_dir($save_dir)) {
         mkdir($save_dir, 0777, true);
     }
     if (file_exists($view_file)) {
         $image = new OC_Image($view_file);
     } else {
         $image_path = OC_Filesystem::getLocalFile($image_path);
         if (!file_exists($image_path)) {
             return null;
         }
         $image = new OC_Image($image_path);
         if ($image->valid()) {
             $image->resize(1200);
             $image->fixOrientation();
             $image->save($view_file);
         }
     }
     if ($image->valid()) {
         return $image;
     } else {
         $image->destroy();
     }
     return null;
 }
<?php

// Get the data
$imageData = $_POST['canv_data'];
$title = rtrim($_POST['title'], 'pdf');
$location = urldecode(dirname($_POST['location']));
if ($location != '/') {
    $location = $location . '/';
}
$filteredData = substr($imageData, strpos($imageData, ",") + 1);
$owner = OCP\USER::getUser();
$save_dir = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/reader';
$save_dir .= $location;
$thumb_file = $save_dir . $title;
if (!is_dir($save_dir)) {
    mkdir($save_dir, 0777, true);
}
$image = new OC_Image($filteredData);
if ($image->valid()) {
    $image->centerCrop(100);
    $image->fixOrientation();
    $image->save($thumb_file . 'png');
}