public function importTranslations($replace = false)
 {
     $counter = 0;
     foreach ($this->files->directories($this->app->langPath()) as $langPath) {
         $locale = basename($langPath);
         foreach ($this->files->allFiles($langPath) as $file) {
             $group = $file->getRelativePathname();
             $group = str_replace('.' . $this->files->extension($group), '', $group);
             if (in_array($group, $this->config['exclude_groups'])) {
                 continue;
             }
             $translations = \Lang::getLoader()->load($locale, $group);
             if ($translations && is_array($translations)) {
                 foreach (array_dot($translations) as $key => $value) {
                     $value = (string) $value;
                     $translation = Translation::firstOrNew(array('locale' => $locale, 'group' => $group, 'key' => $key));
                     // Check if the database is different then the files
                     $newStatus = $translation->value === $value ? Translation::STATUS_SAVED : Translation::STATUS_CHANGED;
                     if ($newStatus !== (int) $translation->status) {
                         $translation->status = $newStatus;
                     }
                     // Only replace when empty, or explicitly told so
                     if ($replace || !$translation->value) {
                         $translation->value = $value;
                     }
                     $translation->save();
                     $counter++;
                 }
             }
         }
     }
     return $counter;
 }
Example #2
0
 public function get($path, array $data = array())
 {
     $filename = $this->files->name($path) . '.' . $this->files->extension($path);
     $compile_path = \Config::get('view.compiled') . DIRECTORY_SEPARATOR . $filename;
     $template_last_modified = $this->files->lastModified($path);
     $cache_last_modified = $this->files->isFile($compile_path) ? $this->files->lastModified($compile_path) : $template_last_modified;
     $view = $this->files->get($path);
     $app = app();
     // $m = new Mustache_Engine($app['config']->get('handlelars'));
     // Configuration
     $cache_disabled = false;
     $helpers = \Config::get('handlelars.helpers');
     // Precompile templates to view cache when necessary
     $compile = $template_last_modified >= $cache_last_modified || $cache_disabled;
     if ($compile) {
         $tpl = LightnCandy::compile($view, compact('helpers'));
         $this->files->put($compile_path, $tpl);
     }
     if (isset($data['__context']) && is_object($data['__context'])) {
         $data = $data['__context'];
     } else {
         $data = array_map(function ($item) {
             return is_object($item) && method_exists($item, 'toArray') ? $item->toArray() : $item;
         }, $data);
     }
     $renderer = $this->files->getRequire($compile_path);
     return $renderer($data);
 }
Example #3
0
 /**
  * Normalize the Twig template name to a name the ViewFinder can use
  *
  * @param  string $name Template file name.
  * @return string The parsed name
  */
 protected function normalizeName($name)
 {
     if ($this->files->extension($name) === $this->extension) {
         $name = substr($name, 0, -(strlen($this->extension) + 1));
     }
     return $name;
 }
 public function publishMigration($filePath)
 {
     if ($this->files->extension($filePath) === 'php') {
         $fullPath = $this->createBaseMigration($filePath);
         $originalMigration = $this->files->get($filePath);
         $this->files->put($fullPath, $originalMigration);
     }
 }
Example #5
0
 public function enqueue($handle, $path, $dependencies = [], $version = 0, $footer = false, $area = self::FRONT, $type = null)
 {
     if (empty($type) && $this->filesystem->exists($path)) {
         $extension = $this->filesystem->extension($path);
         $type = $extension == 'css' ? 'style' : 'script';
     }
     $path = str_replace(public_path(), '', $path);
     $this->add($handle, $path, $dependencies, $version, $footer, $area, $type);
 }
Example #6
0
 /**
  * Get file path based on request pathinfo
  *
  * @param \Illuminate\Http\Request $request
  * @return string
  */
 public function getFilePath(Request $request)
 {
     $pathinfo = $request->getPathInfo();
     if ('' == $this->filesystem->extension($pathinfo)) {
         $file = 'index.html';
         $dir = trim($pathinfo, '/');
     } else {
         $file = basename($pathinfo);
         $dir = trim(dirname($pathinfo), '/');
     }
     if (true === empty($dir)) {
         return "{$this->outputDir}/{$file}";
     }
     return "{$this->outputDir}/{$dir}/{$file}";
 }
 /**
  * Handle the command
  *
  * @param $command
  * @return mixed
  */
 public function handle($command)
 {
     $client = S3Client::factory(array('key' => $this->config->get('services.s3.key'), 'secret' => $this->config->get('services.s3.secret')));
     /*
      * Upload image to S3
      */
     $filesystem = new Flysystem(new Adapter($client, $this->config->get('sightseeing.s3-bucket')));
     $extension = $this->filesystem->extension($command->image->getClientOriginalName());
     $filename = sha1(time() . time()) . ".{$extension}";
     $filesystem->write($filename, file_get_contents($command->image), ['visibility' => 'public']);
     /*
      * Create record on the database
      */
     $this->sightRepository->addImageById($command->id, $filename);
 }
Example #8
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // 从数据库中获取的ArticleTag集合
     $tags = \App\Model\Tag::all();
     // 初始化博客的路径
     $dir = "/root/blog";
     $file_system = new Filesystem();
     $files = $file_system->allFiles($dir);
     foreach ($files as $file) {
         $file_extension = $file_system->extension($file);
         if ($file_extension != 'md') {
             continue;
         }
         $create_time_stamp = $file_system->lastModified($file);
         $create_time = gmdate("Y-m-d", $create_time_stamp);
         $file_content = $file_system->get($file);
         $file_name = preg_replace('/^.+[\\\\\\/]/', '', $file);
         $file_name = explode(".md", $file_name);
         $blog_name = $file_name[0];
         $last_dir = dirname($file);
         $current_tag_name = preg_replace('/^.+[\\\\\\/]/', '', $last_dir);
         $article_type_id = 0;
         foreach ($tags as $tag) {
             $tag_name = $tag->name;
             if (strcmp($current_tag_name, $tag_name) == 0) {
                 $article_type_id = $tag->id;
                 break;
             }
         }
         $article_id = \App\Model\Article::create(['cate_id' => $article_type_id, 'user_id' => 1, 'title' => $blog_name, 'content' => $file_content, 'tags' => $article_type_id, 'created_at' => $create_time, 'updated_at' => $create_time])->id;
         \App\Model\ArticleStatus::create(['art_id' => $article_id, 'view_number' => 0]);
     }
 }
 public function execute($basepath, $filename)
 {
     $path = $basepath . '/' . $filename;
     $extension = $this->filesystem->extension($filename);
     $filename = str_replace('.' . $extension, null, $filename);
     $count = 0;
     while ($this->filesystem->exists($path) || in_array($path, static::$names)) {
         $count++;
         $path = $basepath . '/' . $filename . '-' . $count . '.' . $extension;
     }
     static::$names[] = $path;
     if ($count === 0) {
         return $filename . '.' . $extension;
     }
     return $filename . '-' . $count . '.' . $extension;
 }
Example #10
0
 /**
  * Retorna a imagem de homologacao em formato image inline.
  *
  * @return null|string
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 protected function getImageHomolog()
 {
     $img = __DIR__ . '/Templates/homologacao.png';
     // Verificar se arquivo da logo existe
     if ($this->files->exists($img) != true) {
         return;
     }
     $ext = strtolower($this->files->extension($img));
     $buffer = $this->files->get($img);
     return 'data:image/' . $ext . ';base64,' . base64_encode($buffer);
 }
 /**
  * Return all language messages.
  *
  * @return array
  *
  * @throws \Exception
  */
 protected function getMessages()
 {
     $messages = [];
     $path = $this->sourcePath;
     if (!$this->file->exists($path)) {
         throw new \Exception("{$path} doesn't exists!");
     }
     foreach ($this->file->allFiles($path) as $file) {
         $pathName = $file->getRelativePathName();
         if ($this->file->extension($pathName) !== 'php') {
             continue;
         }
         if ($this->isMessagesExcluded($pathName)) {
             continue;
         }
         $key = substr($pathName, 0, -4);
         $key = str_replace('\\', '.', $key);
         $key = str_replace('/', '.', $key);
         $messages[$key] = (include "{$path}/{$pathName}");
     }
     return $messages;
 }
 /**
  * Return assets as a string
  *
  * @param type
  * @return string
  */
 public function dumpAssetsAsString($type)
 {
     $fs = new Filesystem();
     $files = $fs->allFiles(__DIR__ . '/Assets');
     $content = '';
     foreach ($files as $file) {
         if ($fs->extension($file) != $type) {
             continue;
         }
         $content .= file_get_contents($file) . "\n";
     }
     return $content;
 }
Example #13
0
 /**
  * Retorna a logo informada em formato image inline.
  *
  * @return null|string
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 protected function getLogo()
 {
     // Verificar se logo foi informada
     if ($this->logo === false || is_null($this->logo) || $this->logo == '') {
         return;
     }
     // Verificar se foi informado direto o buffer
     if (@is_file($this->logo) != true) {
         return 'data:image/png;base64,' . base64_encode($this->logo);
     }
     // Verificar se arquivo da logo existe
     if ($this->files->exists($this->logo) != true) {
         return;
     }
     $ext = strtolower($this->files->extension($this->logo));
     $buffer = $this->files->get($this->logo);
     return 'data:image/' . $ext . ';base64,' . base64_encode($buffer);
 }
Example #14
0
 /**
  * @param $key
  * @param array $opinions
  * @return mixed
  */
 public function position($key, $opinions = [])
 {
     $config = $this->config->get('page.recommends');
     $config = array_merge($config[$key], $opinions);
     $articles = ArticleRecommend::wherePosition($key);
     if (isset($opinions['limit']) && $opinions['limit'] > 0) {
         $articles->take($config['limit']);
     }
     $articles = $articles->orderBy('created_at', 'desc')->get();
     if (isset($config['thumbnail']) && is_array($config['thumbnail'])) {
         foreach ($articles as $k => $article) {
             $article = Article::find($article->article_id);
             if ($article) {
                 preg_match_all("/<img([^>]*)\\s*src=('|\")([^'\"]+)('|\")/", $article->content, $matches);
                 $hash = '';
                 $thumbnail = '';
                 if ($matches && $matches[3]) {
                     $matches = array_unique($matches[3]);
                     if ($matches[0] && $this->file->exists(public_path($matches[0]))) {
                         $thumbnail = $matches[0];
                         $hash = hash_file('md5', public_path($matches[0]), false);
                     }
                 }
                 if ($thumbnail && $hash) {
                     $path = '/uploads/thumbnails/' . $config['thumbnail']['width'] . 'X' . $config['thumbnail']['height'] . '/' . $hash . '.' . $this->file->extension(public_path($thumbnail));
                     $directory = public_path('/uploads/thumbnails/' . $config['thumbnail']['width'] . 'X' . $config['thumbnail']['height'] . '/');
                     if (!$this->file->isDirectory($directory)) {
                         $this->file->makeDirectory($directory, 0777, true, true);
                     }
                     if (!$this->file->exists(public_path($path))) {
                         $image = Image::make($thumbnail, $config['thumbnail']);
                         $image->save(public_path($path));
                     }
                     $article->thumbnail = $path;
                 }
                 $articles->put($k, $article);
             } else {
                 $articles->forget($k);
             }
         }
     }
     return $this->view->make($config['template'])->withArticles($articles);
 }
Example #15
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $tag_array = array();
     $first_add = true;
     $dir = "/root/blog";
     $file_system = new Filesystem();
     $files = $file_system->allFiles($dir);
     foreach ($files as $file) {
         $file_extension = $file_system->extension($file);
         if ($file_extension != 'md') {
             continue;
         }
         $last_dir = dirname($file);
         $tag_name = preg_replace('/^.+[\\\\\\/]/', '', $last_dir);
         $create_time_stamp = $file_system->lastModified($file);
         $create_time = gmdate("Y-m-d", $create_time_stamp);
         if ($first_add) {
             $tag_info = array();
             $tag_info[0] = $tag_name;
             $tag_info[1] = $create_time;
             $tag_array[0] = $tag_info;
             $first_add = false;
         }
         $is_new = true;
         foreach ($tag_array as $tag) {
             if (strcmp($tag[0], $tag_name) == 0) {
                 $is_new = false;
             }
         }
         if ($is_new) {
             $tag_count = count($tag_array);
             $tag_info = array();
             $tag_info[0] = $tag_name;
             $tag_info[1] = $create_time;
             $tag_array[$tag_count] = $tag_info;
         }
     }
     foreach ($tag_array as $tag_io) {
         \App\Model\Tag::create(['name' => $tag_io[0]]);
         \App\Model\Category::create(['cate_name' => $tag_io[0], 'as_name' => $tag_io[0], 'parent_id' => 0, 'seo_key' => $tag_io[0], 'seo_desc' => $tag_io[0], 'created_at' => $tag_io[1], 'updated_at' => $tag_io[1]]);
     }
 }
Example #16
0
function getFiles()
{
    $fs = new Filesystem();
    $dir = $fs->directories('../Repo');
    $array_of_files = [];
    foreach ($dir as $directories) {
        $files = $fs->files($directories);
        foreach ($files as $file) {
            if ($fs->extension($file) === "xml") {
                $file = str_replace('/', '-', str_replace('../Repo/', '', $file));
                $n_arr = [];
                $n_arr['file'] = $file;
                array_push($array_of_files, $n_arr);
            }
        }
    }
    header('Content-type: application/json');
    echo json_encode($array_of_files);
    exit;
}
Example #17
0
 /**
  * Provide the File as a Public Preview.
  *
  * @param string $encFileName
  *
  * @return Download
  */
 public function asPreview($encFileName, Filesystem $fileSystem)
 {
     try {
         $fileName = CryptoServiceFacade::url_decode($encFileName);
         if (Config::get('quarx.storage-location') === 'local' || Config::get('quarx.storage-location') === null) {
             $filePath = storage_path('app/' . $fileName);
             $contentType = $fileSystem->mimeType($filePath);
             $ext = '.' . strtoupper($fileSystem->extension($filePath));
         } else {
             $filePath = Storage::disk(Config::get('quarx.storage-location', 'local'))->url($fileName);
             $fileTool = new SplFileInfo($filePath);
             $ext = $fileTool->getExtension();
             $contentType = $this->getMimeType($ext);
         }
         if (stristr($contentType, 'image')) {
             $headers = ['Content-Type' => $contentType];
             if (Config::get('quarx.storage-location') === 'local' || Config::get('quarx.storage-location') === null) {
                 return response()->download($filePath, basename($filePath), $headers);
             } else {
                 $fileContent = Storage::disk(Config::get('quarx.storage-location', 'local'))->get($fileName);
                 return Response::make($fileContent, 200, ['Content-Type' => $contentType, 'Content-Disposition' => 'attachment; filename="' . $fileName . '"']);
             }
         } else {
             $color = '#' . str_pad(dechex(mt_rand(0, 0xffffff)), 6, '0', STR_PAD_LEFT);
             $img = Image::make(__DIR__ . '/../Assets/Images/blank.jpg');
             $img->fill($color);
             $img->text($ext, 145, 145, function ($font) {
                 $font->file(__DIR__ . '/../Assets/Fonts/SourceSansPro-Semibold.otf');
                 $font->size(36);
                 $font->color('#111111');
                 $font->align('center');
                 $font->valign('center');
                 $font->angle(45);
             });
             return $img->response('jpg');
         }
     } catch (Exception $e) {
         return Response::make('file not found');
     }
 }
Example #18
0
function getFiles()
{
    $fs = new Filesystem();
    $dir = $fs->directories('../Repo');
    $array_of_files = [];
    foreach ($dir as $directories) {
        $files = $fs->files($directories);
        foreach ($files as $file) {
            if ($fs->extension($file) === "xml") {
                $file = str_replace('/', '-', str_replace('../Repo/', '', $file));
                $n_arr = [];
                $n_arr['file'] = $file;
                array_push($array_of_files, $n_arr);
            }
        }
    }
    header('Content-type: application/json');
    echo json_encode($array_of_files);
    logMessage("Return list of files: getFiles " . date('m/d/Y h:i:s') . ".\n");
    //log something
    exit;
}
Example #19
0
 /**
  * Extract the file extension from a file path.
  *
  * @param string $path
  * @return string 
  * @static 
  */
 public static function extension($path)
 {
     return \Illuminate\Filesystem\Filesystem::extension($path);
 }
 /**
  * Handle the command
  */
 public function fire()
 {
     $environment = $this->config->get('app.env');
     $gitSnifferEnv = $this->config->get('git-sniffer.env');
     if ($environment !== $gitSnifferEnv) {
         return;
     }
     $phpcsBin = $this->config->get('git-sniffer.phpcs_bin');
     $eslintBin = $this->config->get('git-sniffer.eslint_bin');
     $eslintConfig = $this->config->get('git-sniffer.eslint_config');
     $eslintIgnorePath = $this->config->get('git-sniffer.eslint_ignore_path');
     if (!empty($phpcsBin)) {
         if (!$this->files->exists($phpcsBin)) {
             $this->error('PHP CodeSniffer bin not found');
             exit(1);
         }
     }
     if (!empty($eslintBin)) {
         if (!$this->files->exists($eslintBin)) {
             $this->error('ESLint bin not found');
             exit(1);
         } elseif (!$this->files->exists($eslintConfig)) {
             $this->error('ESLint config file not found');
             exit(1);
         }
         if (!empty($eslintIgnorePath)) {
             if (!$this->files->exists($eslintIgnorePath)) {
                 $this->error('ESLint ignore file not found');
                 exit(1);
             }
         }
     }
     if (empty($phpcsBin) && empty($eslintBin)) {
         $this->error('Eslint bin and Phpcs bin are not configured');
         exit(1);
     }
     $revision = trim(shell_exec('git rev-parse --verify HEAD'));
     $against = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
     if (!empty($revision)) {
         $against = 'HEAD';
     }
     //this is the magic:
     //retrieve all files in staging area that are added, modified or renamed
     //but no deletions etc
     $files = trim(shell_exec("git diff-index --name-only --cached --diff-filter=ACMR {$against} --"));
     if (empty($files)) {
         exit(0);
     }
     $tempStaging = $this->config->get('git-sniffer.temp');
     //create temporary copy of staging area
     if ($this->files->exists($tempStaging)) {
         $this->files->deleteDirectory($tempStaging);
     }
     $fileList = explode("\n", $files);
     $validPhpExtensions = $this->config->get('git-sniffer.phpcs_extensions');
     $validEslintExtensions = $this->config->get('git-sniffer.eslint_extensions');
     $validFiles = [];
     foreach ($fileList as $l) {
         if (!empty($phpcsBin)) {
             if (in_array($this->files->extension($l), $validPhpExtensions)) {
                 $validFiles[] = $l;
             }
         }
         if (!empty($eslintBin)) {
             if (in_array($this->files->extension($l), $validEslintExtensions)) {
                 $validFiles[] = $l;
             }
         }
     }
     //Copy contents of staged version of files to temporary staging area
     //because we only want the staged version that will be commited and not
     //the version in the working directory
     if (empty($validFiles)) {
         exit(0);
     }
     $this->files->makeDirectory($tempStaging);
     $phpStaged = [];
     $eslintStaged = [];
     foreach ($validFiles as $f) {
         $id = shell_exec("git diff-index --cached {$against} \"{$f}\" | cut -d \" \" -f4");
         if (!$this->files->exists($tempStaging . '/' . $this->files->dirname($f))) {
             $this->files->makeDirectory($tempStaging . '/' . $this->files->dirname($f), 0755, true);
         }
         $output = shell_exec("git cat-file blob {$id}");
         $this->files->put($tempStaging . '/' . $f, $output);
         if (!empty($phpcsBin)) {
             if (in_array($this->files->extension($f), $validPhpExtensions)) {
                 $phpStaged[] = '"' . $tempStaging . '/' . $f . '"';
             }
         }
         if (!empty($eslintBin)) {
             if (in_array($this->files->extension($f), $validEslintExtensions)) {
                 $eslintStaged[] = '"' . $tempStaging . '/' . $f . '"';
             }
         }
     }
     $eslintOutput = null;
     $phpcsOutput = null;
     if (!empty($phpcsBin) && !empty($phpStaged)) {
         $standard = $this->config->get('git-sniffer.standard');
         $encoding = $this->config->get('git-sniffer.encoding');
         $ignoreFiles = $this->config->get('git-sniffer.phpcs_ignore');
         $phpcsExtensions = implode(',', $validPhpExtensions);
         $sniffFiles = implode(' ', $phpStaged);
         $phpcsIgnore = null;
         if (!empty($ignoreFiles)) {
             $phpcsIgnore = ' --ignore=' . implode(',', $ignoreFiles);
         }
         $phpcsOutput = shell_exec("\"{$phpcsBin}\" -s --standard={$standard} --encoding={$encoding} --extensions={$phpcsExtensions}{$phpcsIgnore} {$sniffFiles}");
     }
     if (!empty($eslintBin) && !empty($eslintStaged)) {
         $eslintFiles = implode(' ', $eslintStaged);
         $eslintIgnore = ' --no-ignore';
         if (!empty($eslintIgnorePath)) {
             $eslintIgnore = ' --ignore-path "' . $eslintIgnorePath . '"';
         }
         $eslintOutput = shell_exec("\"{$eslintBin}\" -c \"{$eslintConfig}\"{$eslintIgnore} --quiet  {$eslintFiles}");
     }
     $this->files->deleteDirectory($tempStaging);
     if (empty($phpcsOutput) && empty($eslintOutput)) {
         exit(0);
     } else {
         if (!empty($phpcsOutput)) {
             $this->error($phpcsOutput);
         }
         if (!empty($eslintOutput)) {
             $this->error($eslintOutput);
         }
         exit(1);
     }
 }
 public function rename()
 {
     $this->login();
     set_time_limit(0);
     $file = new Filesystem();
     $re = $file->files('/Users/tingliu/Downloads/head_img');
     $count = 1;
     foreach ($re as $key => $path) {
         $new_name = $count . '.' . $file->extension($path);
         $path_seg = explode('/', $path);
         array_pop($path_seg);
         $new_path = implode('/', $path_seg);
         $new_path = '/' . $new_path . '/' . $new_name;
         $file->move($path, $new_path);
         $count++;
     }
     echo "DONE";
 }
Example #22
0
 /**
  * @param resource $im
  * @param string   $string
  */
 private function drawString(&$im, $string)
 {
     // Check whether we have true-type fonts and if so use them
     $ttf_fonts = [];
     if (function_exists('imagefttext')) {
         $fonts = $this->files->files(base_path('resources/captcha_fonts'));
         foreach ($fonts as $font) {
             if ($this->files->extension($font) == 'ttf') {
                 $ttf_fonts[] = $font;
             }
         }
     }
     $spacing = $this->img_width / mb_strlen($string);
     $string_length = mb_strlen($string);
     for ($i = 0; $i < $string_length; ++$i) {
         // Using TTF fonts
         if (!empty($ttf_fonts)) {
             // Select a random font size
             $font_size = mt_rand($this->min_size, $this->max_size);
             // Select a random font
             $font = array_rand($ttf_fonts);
             $font = $ttf_fonts[$font];
             // Select a random rotation
             $rotation = mt_rand($this->min_angle, $this->max_angle);
             // Set the colour
             $r = mt_rand(0, 200);
             $g = mt_rand(0, 200);
             $b = mt_rand(0, 200);
             $color = imagecolorallocate($im, $r, $g, $b);
             // Fetch the dimensions of the character being added
             $dimensions = imageftbbox($font_size, $rotation, $font, $string[$i], array());
             $string_width = $dimensions[2] - $dimensions[0];
             $string_height = $dimensions[3] - $dimensions[5];
             // Calculate character offsets
             //$pos_x = $pos_x + $string_width + ($string_width/4);
             $pos_x = $spacing / 4 + $i * $spacing;
             $pos_y = ceil($this->img_height - $string_height / 2);
             // Draw a shadow
             $shadow_x = mt_rand(-3, 3) + $pos_x;
             $shadow_y = mt_rand(-3, 3) + $pos_y;
             $shadow_color = imagecolorallocate($im, $r + 20, $g + 20, $b + 20);
             imagefttext($im, $font_size, $rotation, $shadow_x, $shadow_y, $shadow_color, $font, $string[$i], array());
             // Write the character to the image
             imagefttext($im, $font_size, $rotation, $pos_x, $pos_y, $color, $font, $string[$i], array());
         } else {
             // Get width/height of the character
             $string_width = imagefontwidth(5);
             $string_height = imagefontheight(5);
             // Calculate character offsets
             $pos_x = $spacing / 4 + $i * $spacing;
             $pos_y = $this->img_height / 2 - $string_height - 10 + mt_rand(-3, 3);
             // Create a temporary image for this character
             if ($this->getGdVersion() >= 2) {
                 $temp_im = imagecreatetruecolor(15, 20);
             } else {
                 $temp_im = imagecreate(15, 20);
             }
             $bg_color = imagecolorallocate($temp_im, 255, 255, 255);
             imagefill($temp_im, 0, 0, $bg_color);
             imagecolortransparent($temp_im, $bg_color);
             // Set the colour
             $r = mt_rand(0, 200);
             $g = mt_rand(0, 200);
             $b = mt_rand(0, 200);
             $color = imagecolorallocate($temp_im, $r, $g, $b);
             // Draw a shadow
             $shadow_x = mt_rand(-1, 1);
             $shadow_y = mt_rand(-1, 1);
             $shadow_color = imagecolorallocate($temp_im, $r + 50, $g + 50, $b + 50);
             imagestring($temp_im, 5, 1 + $shadow_x, 1 + $shadow_y, $string[$i], $shadow_color);
             imagestring($temp_im, 5, 1, 1, $string[$i], $color);
             // Copy to main image
             imagecopyresized($im, $temp_im, $pos_x, $pos_y, 0, 0, 40, 55, 15, 20);
             imagedestroy($temp_im);
         }
     }
 }
Example #23
0
 /**
  * Checks if a given file is a markdown file
  *
  * @param string $file
  * @return bool
  */
 protected function isMarkdownFile($file)
 {
     return $this->filesystem->extension($file) === 'md';
 }
Example #24
0
 /**
  * Hashed file name generate.
  *
  * Generate a uniqe name to be file name.
  *
  * @param   string  $file_name
  * @return  string
  */
 protected function name($filename)
 {
     // Get extension.
     $extension = $this->files->extension($filename);
     return md5(Str::random(30) . time()) . '.' . $extension;
 }
Example #25
0
 /**
  * Publish an image to the publish directory.
  *
  * @param $path
  */
 protected function publish($path)
 {
     $path = ltrim($path, '/');
     $this->files->makeDirectory((new \SplFileInfo($path))->getPath(), 0777, true, true);
     if ($this->files->extension($path) == 'svg') {
         $this->files->put($path, $this->dumpImage());
         return;
     }
     if (!($image = $this->makeImage())) {
         return;
     }
     if (function_exists('exif_read_data') && $image->exif('Orientation') && $image->exif('Orientation') > 1) {
         $this->addAlteration('orientate');
     }
     if (!$this->getAlterations() && ($content = $this->dumpImage())) {
         $this->files->put($this->directory . $path, $content);
         return;
     }
     if (is_callable('exif_read_data') && in_array('orientate', $this->getAlterations())) {
         $this->setAlterations(array_unique(array_merge(['orientate'], $this->getAlterations())));
     }
     foreach ($this->getAlterations() as $method => $arguments) {
         if ($method == 'resize') {
             $this->guessResizeArguments($arguments);
         }
         if (in_array($method, $this->getAllowedMethods())) {
             if (is_array($arguments)) {
                 call_user_func_array([$image, $method], $arguments);
             } else {
                 call_user_func([$image, $method], $arguments);
             }
         }
     }
     $image->save($this->directory . $path, $this->getQuality());
 }