public function marcaAgua($imagem, $pastas) { $img = WideImage::load($pastas . '' . $imagem); $marca = WideImage::load('../../View/webroot/img/marca.png'); $novaImagem = $img->merge($marca, 50, 50, 50); $novaImagem->saveToFile($pastas . '' . $imagem); }
function execute($image) { $mask = \WideImage\WideImage::load(DEMO_PATH . 'masks/' . $this->fields['mask']->value); $left = $this->fields['left']->value; $top = $this->fields['top']->value; return $image->applyMask($mask, $left, $top); }
public function testRotate45() { $img = WideImage::load(IMG_PATH . '100x100-rainbow.png'); $new = $img->rotate(45); $this->assertEquals(142, $new->getWidth()); $this->assertEquals(142, $new->getHeight()); }
public function process(Task $task = null) { if (empty($task)) { $task = new Task($this->path, $this->filename, $this->extension, $this->config['public_path']); } // Can we read the original file and write in the original path? if (!$task->isValid()) { return $this->halt(); } // Can we operate in this path? if (!preg_match($this->config['path_mask'], trim(str_replace($this->config['public_path'], '', $task->origPath), DIRECTORY_SEPARATOR))) { return $this->halt(); } // Is a valid task name and can we call the action? $callable = $this->getActionCallable($task->name); if ($callable === false) { return $this->halt(); } else { $task->image = \WideImage\WideImage::load($task->origFile); // Create destination path if (!file_exists($task->destPath) and !is_dir($task->destPath)) { @mkdir($task->destPath, 0775, true); } if (call_user_func($callable, $task) !== false) { // If the action does not return false explicitly... $this->reload(); // SUCCESS exit point: reload the image URL } } $this->halt(); }
function execute($image, $request) { $overlay = \WideImage\WideImage::load(DEMO_PATH . 'images/' . $this->fields['overlay']->value); $left = $this->fields['left']->value; $top = $this->fields['top']->value; $opacity = $this->fields['opacity']->value; return $image->merge($overlay, $left, $top, $opacity); }
/** * @param File|resource|string $file_in * @return ImageManipulatorInterface */ public static function read($file_in) { $self = new self(); if (is_object($file_in) && $file_in instanceof File) { $file_in = $file_in->getGDHandle(); } $self->_wi = WideImage::load($file_in); return $self; }
public function testApplyFilter() { $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif'); $result = $img->applyFilter(IMG_FILTER_EDGEDETECT); $this->assertTrue($result instanceof TrueColorImage); $this->assertTrue($result->isTransparent()); $this->assertEquals(100, $result->getWidth()); $this->assertEquals(100, $result->getHeight()); }
public function testApplyConvolution() { $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif'); $result = $img->applyConvolution(array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1)), 1, 220); $this->assertTrue($result instanceof TrueColorImage); $this->assertTrue($result->isTransparent()); $this->assertEquals(100, $result->getWidth()); $this->assertEquals(100, $result->getHeight()); }
public function test() { $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif'); $result = $img->unsharp(10, 5, 1); $this->assertTrue($result instanceof PaletteImage); $this->assertTrue($result->isTransparent()); $this->assertEquals(100, $result->getWidth()); $this->assertEquals(100, $result->getHeight()); }
public function testAutocropHalfImageBug() { $img = WideImage::load(IMG_PATH . '100x100-red-spot-half-cut.png'); $cropped = $img->autocrop(); $this->assertTrue($cropped instanceof TrueColorImage); $this->assertEquals(22, $cropped->getWidth()); $this->assertEquals(23, $cropped->getHeight()); $this->assertRGBNear($cropped->getRGBAt(10, 10), 255, 0, 0); }
public function testTransparentCorner() { $img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png'); $res = $img->roundCorners(30, null, WideImage::SIDE_ALL); $this->assertEquals(100, $res->getWidth()); $this->assertEquals(100, $res->getHeight()); $this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127)); $this->assertRGBAt($res, 95, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127)); $this->assertRGBAt($res, 95, 95, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127)); $this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127)); }
public function testGetMaskPNGAlpha() { $img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png'); $mask = $img->getMask(); $this->assertTrue($mask instanceof TrueColorImage); $this->assertFalse($mask->isTransparent()); $this->assertEquals(100, $mask->getWidth()); $this->assertEquals(100, $mask->getHeight()); $this->assertRGBNear($mask->getRGBAt(25, 25), 192, 192, 192); $this->assertRGBNear($mask->getRGBAt(75, 25), 128, 128, 128); $this->assertRGBNear($mask->getRGBAt(75, 75), 64, 64, 64); $this->assertRGBNear($mask->getRGBAt(25, 75), 0, 0, 0); }
public function testApplyMask() { $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif'); $mask = WideImage::load(IMG_PATH . '75x25-gray.png'); $result = $img->applyMask($mask); $this->assertTrue($result instanceof TrueColorImage); $this->assertTrue($result->isTransparent()); $this->assertEquals(100, $result->getWidth()); $this->assertEquals(100, $result->getHeight()); $this->assertRGBNear($result->getRGBAt(10, 10), 255, 255, 255); $this->assertRGBNear($result->getRGBAt(30, 10), 255, 255, 0, 64); $this->assertRGBNear($result->getRGBAt(60, 10), 0, 0, 255, 0); }
public function testPNGAlpha() { $img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png'); $gray = $img->asGrayscale(); $this->assertTrue($gray instanceof TrueColorImage); $this->assertEquals(100, $gray->getWidth()); $this->assertEquals(100, $gray->getHeight()); $this->assertRGBNear($gray->getRGBAt(25, 25), 29, 29, 29, 32); $this->assertRGBNear($gray->getRGBAt(75, 25), 29, 29, 29, 64); $this->assertRGBNear($gray->getRGBAt(75, 75), 29, 29, 29, 96); $this->assertRGBNear($gray->getRGBAt(25, 75), 0, 0, 0, 127); $this->assertFalse($gray->isTransparent()); }
public function testMergeOpacityFull() { $img = WideImage::load(IMG_PATH . '100x100-color-hole.png'); $overlay = WideImage::load(IMG_PATH . '100x100-square-overlay.png'); $res = $img->merge($overlay, 0, 0, 100); $this->assertEquals(100, $res->getWidth()); $this->assertEquals(100, $res->getHeight()); $this->assertRGBAt($res, 5, 5, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0)); $this->assertRGBAt($res, 40, 40, array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0)); $this->assertRGBAt($res, 95, 5, array('red' => 0, 'green' => 0, 'blue' => 255, 'alpha' => 0)); $this->assertRGBAt($res, 60, 40, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127)); $this->assertRGBAt($res, 95, 95, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0)); $this->assertRGBAt($res, 60, 60, array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0)); $this->assertRGBAt($res, 5, 95, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0)); $this->assertRGBAt($res, 40, 60, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 0)); }
public function testMirror() { $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif'); $this->assertRGBEqual($img->getRGBAt(5, 5), 255, 255, 0); $this->assertRGBEqual($img->getRGBAt(95, 5), 0, 0, 255); $this->assertRGBEqual($img->getRGBAt(95, 95), 0, 255, 0); $this->assertRGBEqual($img->getRGBAt(5, 95), 255, 0, 0); $new = $img->mirror(); $this->assertTrue($new instanceof PaletteImage); $this->assertEquals(100, $new->getWidth()); $this->assertEquals(100, $new->getHeight()); $this->assertRGBEqual($new->getRGBAt(95, 5), 255, 255, 0); $this->assertRGBEqual($new->getRGBAt(5, 5), 0, 0, 255); $this->assertRGBEqual($new->getRGBAt(5, 95), 0, 255, 0); $this->assertRGBEqual($new->getRGBAt(95, 95), 255, 0, 0); $this->assertTrue($new->isTransparent()); $this->assertRGBEqual($new->getRGBAt(50, 50), $img->getTransparentColorRGB()); }
public function testAsTrueColor() { $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif'); $this->assertTrue($img instanceof PaletteImage); $this->assertTrue($img->isValid()); $copy = $img->asTrueColor(); $this->assertFalse($img->getHandle() === $copy->getHandle()); $this->assertTrue($copy instanceof TrueColorImage); $this->assertTrue($copy->isValid()); $this->assertTrue($copy->isTrueColor()); $this->assertTrue($copy->isTransparent()); $this->assertRGBEqual($copy->getRGBAt(15, 15), 255, 255, 0); $this->assertRGBEqual($copy->getRGBAt(85, 15), 0, 0, 255); $this->assertRGBEqual($copy->getRGBAt(85, 85), 0, 255, 0); $this->assertRGBEqual($copy->getRGBAt(15, 85), 255, 0, 0); $this->assertEquals($copy->getRGBAt(50, 50), $copy->getTransparentColorRGB()); $rgb = $copy->getTransparentColorRGB(); $this->assertRGBEqual($img->getTransparentColorRGB(), $rgb['red'], $rgb['green'], $rgb['blue']); }
public function upload($request) { // obtain the uploaded file, load image and get its details (filename, extension) if (!$request->headers->has('x-filename')) { return new Response('Filename is missing (header X-FILENAME)', 400); } $filename = base64_decode($request->headers->get('x-filename')); $pathinfo = pathinfo($filename); if (!in_array(strtolower($pathinfo['extension']), self::$imageExtensions)) { return $this->json($request, array('status' => 1, 'errMessage' => "{$filename} is not an image file"), 200); } $filename = Utils::sanitizeFilename($pathinfo['filename']); $ext = $pathinfo['extension']; $img = WideImage::load("php://input"); // generate image set $res = $this->generateImageSet($img, $filename, $ext); $res = array('status' => 0, 'srcset' => $res['srcset'], 'ratio' => $res['ratio']); return $this->json($request, $res, 200); }
public static function create($config = []) { if (!empty($config)) { if (!empty($config['tmpName'])) { $dirName = $config['dirName']; $rensize = WideImage::load($config['tmpName']); self::dir($dirName); chmod($dirName, 0777); $big = WWW_ROOT . '/images/' . $dirName . '/big/' . $config['name']; $small = WWW_ROOT . '/images/' . $dirName . '/small/' . $config['name']; $im = imagecreatefromstring($rensize->resize(370, 281)); imagejpeg($im, $small); $imb = imagecreatefromstring($rensize->resize(767, 511)); imagejpeg($imb, $big); chmod($small, 0777); chmod($big, 0777); } } else { return ''; } }
private static function generateThumbnail($image) { $image = WideImage::load($image); $thumb = $image->resize(300, 400); return $thumb; }
public function testSerializePaletteImage() { $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif'); $img2 = unserialize(serialize($img)); $this->assertEquals(get_class($img2), get_class($img)); $this->assertFalse($img2->isTrueColor()); $this->assertTrue($img2->isValid()); $this->assertTrue($img2->isTransparent()); $this->assertEquals($img->getWidth(), $img2->getWidth()); $this->assertEquals($img->getHeight(), $img2->getHeight()); }
public function load($file) { return WideImage::load(IMG_PATH . $file); }
public function testPreserveTransparency() { $img = WideImage::load(IMG_PATH . '100x100-color-hole.gif'); $this->assertTrue($img->isTransparent()); $this->assertRGBEqual($img->getTransparentColorRGB(), 255, 255, 255); $tc = $img->asTrueColor(); $this->assertTrue($tc->isTransparent()); $this->assertRGBEqual($tc->getTransparentColorRGB(), 255, 255, 255); $img = $tc->asPalette(); $this->assertTrue($img->isTransparent()); $this->assertRGBEqual($img->getTransparentColorRGB(), 255, 255, 255); }
/** * @expectedException WideImage\Exception\Exception */ public function testCropCutsAreaNegativePosition() { $img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png'); $cropped = $img->crop(-150, -200, 50, 50); }
/** * Constructor * * @param string $path Path to source image */ public function __construct($path) { $this->source = WideImage::load($path); }
/** * @expectedException WideImage\Exception\InvalidImageSourceException */ public function testEmptyString() { WideImage::load(''); }
/** * Generate source image presets. * * @param Entity $imageEntity Image entity. * @param bool $force Use force to override image if exists. * @return void */ public function generatePresets($imageEntity, $force = false) { $basePath = $this->basePath($imageEntity->model) . DS; $imagePath = $basePath . $imageEntity->filename; $quality = $this->getCorrectQuality(pathinfo($imagePath, PATHINFO_EXTENSION)); $presets = $this->config('presets'); foreach ($presets as $preset => $options) { $dir = $basePath . $preset . DS; $folder = new Folder($dir, true, 0775); $destination = $dir . $imageEntity->filename; if (!$force && file_exists($destination)) { continue; } $wImage = WideImage::load($imagePath); foreach ($options as $action => $params) { if (is_callable($params)) { $wImage = $params($wImage, $imagePath); } else { $wImage = call_user_func_array([$wImage, $action], $params); } } $wImage->saveToFile($destination, $quality); } }
public function load($path) { return WideImage::load($path); }
/** * @param File $file * @param int $width * @param int $height * @return string */ public function getThumbImage(File $file, $width = 200, $height = 200) { $sourceImage = $file->getSavePath(); $resultImage = $file->getSavePath() . '-' . $width . '-' . $height . '.' . $file->getFileExtension(); if (!$this->getCacheFilesystem()->has($resultImage)) { try { $_file = $this->getFilesystem()->read($sourceImage); $image = WideImage::load($_file); $image_data = $image->resize($width, $height, 'outside')->crop('center', 'center', $width, $height)->asString($file->getFileExtension()); $this->getCacheFilesystem()->write($resultImage, $image_data); } catch (\Exception $e) { throw new Exception\RuntimeException('File cannot be saved.', 0, $e); } } $fsAdapter = $this->getCacheFilesystem()->getAdapter(); return str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', $fsAdapter->getPathPrefix() . $resultImage)); }
public function testCopyCombinedChannels() { $img = WideImage::load(IMG_PATH . '100x100-blue-alpha.png'); $copy = $img->getChannels('blue', 'alpha'); $this->assertRGBNear($copy->getRGBAt(25, 25), 0, 0, 255, 0.25 * 127); $this->assertRGBNear($copy->getRGBAt(75, 25), 0, 0, 255, 0.5 * 127); $this->assertRGBNear($copy->getRGBAt(75, 75), 0, 0, 255, 0.75 * 127); $this->assertRGBNear($copy->getRGBAt(25, 75), 0, 0, 0, 127); }