Author: Nick Sagona, III (dev@nolainteractive.com)
Inheritance: extends Pop\Image\AbstractRasterImage
 /**
  * Index method
  *
  * @return void
  */
 public function index()
 {
     if (DB_INTERFACE != '' && DB_NAME != '') {
         Response::redirect(BASE_PATH . APP_URI);
     } else {
         $install = new Model\Install(array('title' => $this->i18n->__('Installation')));
         $form = new Form\Install($this->request->getBasePath() . $this->request->getRequestUri() . '?lang=' . $this->i18n->getLanguage() . '_' . $this->i18n->getLocale(), 'post');
         if (!\Pop\Image\Gd::isInstalled() && !\Pop\Image\Imagick::isInstalled()) {
             $install->set('error', 'Neither the GD or Imagick extensions are installed. Phire CMS 2.0 requires one of them to be installed for graphic manipulation to fully function properly. You can continue with the install, but you will not be able to upload or manipulate image graphics until one of the image extensions is installed.');
         }
         if ($this->request->isPost()) {
             $form->setFieldValues($this->request->getPost(), array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8')));
             if ($form->isValid()) {
                 $install->config($form);
                 $url = isset($install->configWritable) && $install->configWritable ? BASE_PATH . $form->app_uri . '/install/user' : BASE_PATH . APP_URI . '/install/config';
                 Response::redirect($url . '?lang=' . POP_LANG);
             } else {
                 $install->set('form', $form);
                 $this->view = View::factory($this->viewPath . '/index.phtml', $install->getData());
                 $this->view->set('i18n', $this->i18n);
                 $this->send();
             }
         } else {
             $install->set('form', $form);
             $this->view = View::factory($this->viewPath . '/index.phtml', $install->getData());
             $this->view->set('i18n', $this->i18n);
             $this->send();
         }
     }
 }
示例#2
0
文件: gd.php 项目: nicksagona/PopPHP
<?php

require_once '../../bootstrap.php';
use Pop\Color\Space\Rgb;
use Pop\Image\Gd;
try {
    $points = array(array('x' => 320, 'y' => 50), array('x' => 400, 'y' => 100), array('x' => 420, 'y' => 200), array('x' => 280, 'y' => 320), array('x' => 200, 'y' => 180));
    $image = new Gd('new-image.jpg', 640, 480, new Rgb(255, 0, 0));
    $image->setFillColor(new Rgb(0, 0, 255))->setStrokeColor(new Rgb(255, 255, 255))->setStrokeWidth(3)->drawPolygon($points)->output();
    // Calling the destructor destroys the image resource as well
    unset($image);
} catch (\Exception $e) {
    echo $e->getMessage();
}
 /**
  * Edit action method
  *
  * @param  int $id
  * @return void
  */
 public function edit($id)
 {
     $library = new Model\MediaLibrary();
     $library->getById($id);
     $this->prepareView('media/libraries/edit.phtml');
     $this->view->title = 'Media Libraries';
     $this->view->library_name = $library->name;
     $fields = $this->application->config()['forms']['Phire\\Media\\Form\\MediaLibrary'];
     if (\Pop\Image\Gd::isInstalled()) {
         $fields[0]['adapter']['value']['Gd'] = 'Gd';
     }
     if (\Pop\Image\Imagick::isInstalled()) {
         $fields[0]['adapter']['value']['Imagick'] = 'Imagick';
     }
     if (\Pop\Image\Gmagick::isInstalled()) {
         $fields[0]['adapter']['value']['Gmagick'] = 'Gmagick';
     }
     $fields[1]['name']['attributes']['onkeyup'] .= ' phire.changeTitle(this.value);';
     $this->view->form = new Form\MediaLibrary($fields);
     $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($library->toArray());
     if ($this->request->isPost()) {
         $this->view->form->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
             $library = new Model\MediaLibrary();
             $library->update($this->view->form->getFields());
             $this->view->id = $library->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect(BASE_PATH . APP_URI . '/media/libraries/edit/' . $library->id);
         }
     }
     $this->send();
 }
示例#4
0
 public function testConvertExceptionDupeType()
 {
     $this->setExpectedException('Pop\\Image\\Exception');
     $i = new Gd(__DIR__ . '/../tmp/test.gif');
     $i->convert('gif');
 }
示例#5
0
 /**
  * Create CAPTCHA image
  *
  * @return Captcha
  */
 public function createImage()
 {
     $image = new Gd('captcha.gif', $this->width, $this->height);
     $image->setBackgroundColor(255, 255, 255);
     $image->draw()->setStrokeColor($this->lineColor[0], $this->lineColor[1], $this->lineColor[2]);
     // Draw background grid
     for ($y = $this->lineSpacing; $y <= $this->height; $y += $this->lineSpacing) {
         $image->draw()->line(0, $y, $this->width, $y);
     }
     for ($x = $this->lineSpacing; $x <= $this->width; $x += $this->lineSpacing) {
         $image->draw()->line($x, 0, $x, $this->height);
     }
     $image->effect()->border($this->textColor, 0.5);
     $image->type()->setFillColor($this->textColor[0], $this->textColor[1], $this->textColor[2]);
     if (null === $this->font) {
         $image->type()->size(5);
         $textX = round(($this->width - $this->length * 10) / 2);
         $textY = round(($this->height - 16) / 2);
     } else {
         $image->type()->font($this->font)->size($this->size);
         $textX = round(($this->width - $this->length * ($this->size / 1.5)) / 2);
         $textY = round($this->height - ($this->height - $this->size) / 2 + (int) $this->rotate / 2);
     }
     $image->type()->xy($textX, $textY)->text($this->token['value']);
     $this->image = $image;
     return $this;
 }
示例#6
0
 /**
  * Constructor
  *
  * Instantiate a CAPTCHA image object. Valid options are:
  *
  *     $options = array(
  *         'width'      => 75,
  *         'height'     => 25,
  *         'background' => array(200, 200, 200) // R, G, B values for the background color
  *     );
  *
  *     $options = array(
  *         'image'  => 'some-image-background,gif'
  *     );
  *
  * This $forceGd flag forces the object to use the Gd extension. If both are
  * installed, it will default to Imagick unless this flag is set to true.
  *
  * @param array   $options
  * @param boolean $forceGd
  * @throws Exception
  * @return \Pop\Image\Captcha
  */
 public function __construct(array $options, $forceGd = false)
 {
     // Check that at least one of the image extensions is installed
     if (!Gd::isInstalled() && !Imagick::isInstalled()) {
         throw new Exception('Error: At least either the GD or Imagick extension must be installed.');
     }
     if ($forceGd) {
         $class = 'Pop\\Image\\Gd';
     } else {
         $class = Imagick::isInstalled() ? 'Pop\\Image\\Imagick' : 'Pop\\Image\\Gd';
     }
     // Parse through the options
     if (isset($options['image']) && file_exists($options['image'])) {
         $image = $options['image'];
         $w = null;
         $h = null;
     } else {
         if (isset($options['width']) && isset($options['height']) && is_numeric($options['width']) && is_numeric($options['height'])) {
             $image = 'pop-captcha.gif';
             $w = $options['width'];
             $h = $options['height'];
         } else {
             throw new Exception('Error: You must either pass a valid width and height or a valid image in the $options parameter.');
         }
     }
     if (isset($options['background']) && is_array($options['background']) && count($options['background']) == 3) {
         $background = new Rgb($options['background'][0], $options['background'][1], $options['background'][2]);
     } else {
         $background = null;
     }
     // Create new image object
     $this->image = new $class($image, $w, $h, $background);
 }