Esempio n. 1
0
    $response = $app->response();
    $response['Content-Type'] = 'application/json';
    $response->body(json_encode($pictures));
});
$app->get('/pictures/display/:storename', function ($storename) use($app) {
    $store = new Phrenetic\StoreFile('pictures');
    $picture = RMAN\Models\ORM\Picture::where('storename', $storename)->where('default', 1)->first();
    if (empty($picture)) {
        die('FOOBAR');
    }
    $response = $app->response();
    $response['Content-Type'] = $picture->type;
    $response->body($store->get($picture->storename));
});
$app->get('/pictures/resized/:x/:y/:storename', function ($size_x, $size_y, $storename) use($app) {
    $store = new Phrenetic\StoreFile('pictures');
    $q = RMAN\Models\ORM\Picture::where('storename', $storename);
    $db = $q->getQuery();
    $columns = ['pictures.*'];
    if ($size_x) {
        $columns[] = $db->raw('ABS(' . (int) $size_x . ' - width) as wdiff');
        $q->orderBy('wdiff', 'asc');
    }
    if ($size_y) {
        $columns[] = $db->raw('ABS(' . (int) $size_y . ' - height) as hdiff');
        $q->orderBy('hdiff', 'asc');
    }
    $q->select($columns);
    $picture = $q->first();
    if (empty($picture)) {
        die('FOOBAR');
Esempio n. 2
0
#!/usr/bin/env php
<?php 
require_once __DIR__ . '/../init.php';
$step = 256;
$count = RMAN\Models\ORM\Picture::where('default', '=', 0)->count();
$store = new Phrenetic\StoreFile('pictures');
for ($offset = 0; $offset < $count; $offset += $step) {
    $pictures = RMAN\Models\ORM\Picture::where('default', '=', 0)->limit($step)->offset($offset)->get();
    foreach ($pictures as $picture) {
        $fname = $store->filename($picture->resizedname);
        if (is_file($fname)) {
            if (@unlink($fname)) {
                $picture->delete();
            }
        }
    }
}