<?php

/*
 * *************************************************
 * Copyright (C) 2020 Earworks.                    *
 * Codeigniter Project Template Modification       *
 * Please contact our email for more information : *
 * contact@earworks.co.id                          *
 * *************************************************
 */

defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Description of Captcha
 *
 * @author andhy
 */
class Captcha extends CI_Controller {

    public function index() {
        Ci::helpers(['captcha', 'api', 'file']);
//        delete_files(STATIC_PATH . 'captcha' . DIRECTORY_SEPARATOR, false, true);
        $cap = create_captcha([
//            'word' => (ENVIRONMENT == 'development') ? 'word' : null,
            'img_path' => STATIC_PATH . 'captcha' . DIRECTORY_SEPARATOR,
            'img_url' => base_url('img/captcha'),
            'font_path' => STATIC_PATH . '../fonts/lato/Lato-Black.ttf',
            'img_width' => '150',
            'img_height' => 30,
            'expiration' => 7200,
            'word_length' => 6,
            'font_size' => 16,
            'img_id' => 'Imageid',
            'pool' => '123456789abcdefghiklmnpqrstuvwxyzADEFGHJKLMNQRTYZ',
            // White background and border, black text and red grid
            'colors' => [
                'background' => array(255, 255, 255),
                'border' => array(255, 255, 255),
                'text' => array(0, 0, 0),
                'grid' => array(255, 40, 40)
            ]
        ]);
        $this->session->set_userdata('captcha', $cap['word']);
        chmod(STATIC_PATH . 'captcha' . DIRECTORY_SEPARATOR . $cap['filename'], 0777);
        unset($cap['image']);
        return output_blank($cap);
    }

}
