Exemplo n.º 1
0
require_once dirname(__DIR__) . '/src/File.class.php';
require_once dirname(__DIR__) . '/src/JSON.class.php';
/**
 * Example script for FileObject remote synchronization.
 * Install on remote server and adjust require_once.
 *
 * @author Roland Kujundzic <*****@*****.**>
 *
 */
if (!empty($_REQUEST['path']) || !empty($_REQUEST['format'])) {
    return '';
}
// format: misl = md5 + (width + height) + size + last_modified
$format = $_REQUEST['format'];
$path = $_REQUEST['path'];
$res = [];
if (strpos($format, 'm') !== false) {
    $res['md5'] = File::md5($path);
}
if (strpos($format, 'i') !== false) {
    $ii = File::imageInfo($path, false);
    $res['width'] = $ii['width'];
    $res['height'] = $ii['height'];
}
if (strpos($format, 's') !== false) {
    $res['size'] = File::size($path);
}
if (strpos($format, 'l') !== false) {
    $res['last_modified'] = File::last_modified($path);
}
print JSON::encode($res);
Exemplo n.º 2
0
 /**
  * Resize source image and save as target. If wxh is empty you can convert from one image type to another. 
  * Abort if w or h is greater than 2 * original size. Requires convert from ImageMagic.
  *
  * @param string $wxh (e.g. 140x140 or 140x or x140)
  * @param string $source
  * @param string $target (if empty overwrite source)
  */
 public static function resizeImage($wxh, $source, $target = '')
 {
     $info = File::imageInfo($source);
     $resize = '';
     if (!empty($wxh)) {
         list($w, $h) = explode('x', $wxh);
         if ($w < 0 || $w > 2 * $info['width']) {
             throw new Exception('invalid resize width', "{$w} not in ]0, 2 * " . $info['width'] . "]");
         }
         if ($h < 0 || $h > 2 * $info['height']) {
             throw new Exception('invalid resize height', "{$h} not in ]0, 2 * " . $info['height'] . "]");
         }
         $resize = "-resize '{$wxh}'";
     }
     if (empty($target)) {
         $suffix = File::suffix($source, true);
         $base = File::basename($source, true);
         $temp = dirname($source) . '/' . $base . '_' . $wxh . $suffix;
         if (File::exists($temp)) {
             throw new Exception('already resizing or resize failed', $temp);
         }
         \rkphplib\lib\execute("convert {$resize} '{$wxh}' '{$source}' '{$temp}'");
         File::move($temp, $source);
         $target = $source;
     } else {
         \rkphplib\lib\execute("convert {$resize} '{$wxh}' '{$source}' '{$target}'");
     }
     File::exists($target, true);
 }
Exemplo n.º 3
0
 /**
  * Scan $this->path_absolute and set md5, size and last_modified properties.
  * If with and height property exists retrieve image dimensions.
  */
 protected function scanFile()
 {
     $this->md5 = File::md5($this->path_absolute);
     $this->size = File::size($this->path_absolute);
     $this->last_modified = File::lastModified($this->path_absolute);
     if (property_exists($this, 'width') && property_exists($this, 'height')) {
         $ii = File::imageInfo($this->path_absolute);
         $this->width = intval($ii['width']);
         $this->height = intval($ii['height']);
     }
 }