<?php

use Illuminate\Database\Seeder;
use App\Helpers\Helper;
use App\Fortuneteller;

class GenFortuneThumb extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $path = public_path('uploads/image/fortune/');
        $all = Fortuneteller::all();
        foreach ($all as $item) {
        	$name = $item->avatar;
        	if ($name != null && $name != "") {
        	    $this->genImageSize(60, 60, $path, $name);
        	    /*$this->genImageSize(90, 50, $path, $name);
        	    $this->genImageSize(170, 230, $path, $name);*/
        	}
        }
        /*$this->genImageSize(60, 60, $path, 'no-image.png');*/
    }

    public function genImageSize($width, $height, $path, $name) {
        if (file_exists($path . $name) && !file_exists($path . 'thumb_' . $width . 'x' . $height . '/' . $name)) {
            Helper::createThumbFit($path . $name, $path, $width, $height);
            print "Create thumbnail for image " . $width . "x" . $height .": " . $name . "\r\n";
        }
        /*$this->genImageSize($width, $height, $path, 'no-image.png');*/
    }
}
