public function image($request) { if (!$request->request->has('image')) { return new Response('Image URI is missing', 400); } $uri = $request->request->get('image'); if (!$request->request->has('data')) { return new Response('Image transformation data is missing', 400); } $data = $request->request->get('data'); if (!$this->ctx['fs']->has($uri)) { return new Response("Source image not found ({$uri})", 400); } $img = WideImage::loadFromString($this->ctx['fs']->read($uri)); if (Utils::isResourceUrl($uri)) { $info = Utils::resurlinfo($uri); } else { $pathinfo = pathinfo($uri); $info = array('name' => $pathinfo['filename'], 'ext' => $pathinfo['extension']); } $datas = explode(':', $data); $left = $datas[0]; $top = $datas[1]; $width = $datas[2]; $height = $datas[3]; $filename = $info['name']; $ext = $info['ext']; $img = $this->transform_image($img, $top, $left, $width, $height); // 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 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 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(); }
public function testMagicCallDrawRectangle() { $img = WideImage::createTrueColorImage(10, 10); $canvas = $img->getCanvas(); $canvas->filledRectangle(1, 1, 5, 5, $img->allocateColorAlpha(255, 0, 0, 64)); $this->assertRGBAt($img, 3, 3, array('red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 64)); }
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()); }
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); }
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 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()); }
/** * @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 image($uri, $x = '0%', $y = '0%', $w = '100%', $h = '100%') { if (Utils::isURL($uri)) { list($image, $extension) = $this->loadFromURL($uri); //$this->transform(Utils::nameFromURL($uri), $extension, WideImage::loadFromString($image), $x, $y, $w, $h) : } else { $imageName = $this->imageName($uri); $this->transform($imageName['name'], $imageName['extension'], WideImage::loadFromString($this->fs->read($uri)), $x, $y, $w, $h); } }
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 testSaveToFile() { $handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif'); $this->mapper->save($handle, IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'test.gd2'); $this->assertTrue(filesize(IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'test.gd2') > 0); imagedestroy($handle); // file is a valid image $handle = imagecreatefromgd2(IMG_PATH . 'temp' . DIRECTORY_SEPARATOR . 'test.gd2'); $this->assertTrue(WideImage::isValidImageHandle($handle)); imagedestroy($handle); }
public function testResizeCanvasPositionsCorner() { $img = WideImage::createTrueColorImage(20, 20); $black = $img->allocateColor(0, 0, 0); $white = $img->allocateColor(255, 255, 255); $img->fill(0, 0, $black); $res = $img->resizeCanvas(40, 40, 'bottom', 'right', $white); $this->assertRGBAt($res, 5, 5, $white); $this->assertRGBAt($res, 35, 35, $black); $this->assertRGBAt($res, 5, 35, $white); $this->assertRGBAt($res, 35, 5, $white); }
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 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 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); }
/** * Resize the original image - we don't want to save massive copies of everything * @since Version 3.10.0 * @param string $imageSource * @return void */ public static function ResizeOriginal($imageSource) { $sizes = getimagesize($imageSource); if ($sizes[0] <= Image::MAX_WIDTH && $sizes[1] <= Image::MAX_HEIGHT) { return true; } $image = file_get_contents($imageSource); $Image = WideImage::loadFromString($image); $size = $Image->resize(Image::MAX_WIDTH, Image::MAX_HEIGHT, "inside"); file_put_contents($imageSource, $size->asString("jpg", 100)); if (!file_exists($imageSource)) { throw new Exception("Resized image and saved to path, but could not find it after!"); } return true; }
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)); }
/** * Returns an image with a resized canvas * * The image is filled with $color. Use $scale to determine, when to resize. * * @param \WideImage\Image $img * @param smart_coordinate $width * @param smart_coordinate $height * @param smart_coordinate $left * @param smart_coordinate $top * @param int $color * @param string $scale 'up', 'down', 'any' * @param boolean $merge * @return \WideImage\Image */ public function execute($img, $width, $height, $left, $top, $color, $scale, $merge) { $new_width = Coordinate::fix($width, $img->getWidth()); $new_height = Coordinate::fix($height, $img->getHeight()); if ($scale == 'down') { $new_width = min($new_width, $img->getWidth()); $new_height = min($new_height, $img->getHeight()); } elseif ($scale == 'up') { $new_width = max($new_width, $img->getWidth()); $new_height = max($new_height, $img->getHeight()); } $new = WideImage::createTrueColorImage($new_width, $new_height); if ($img->isTrueColor()) { if ($color === null) { $color = $new->allocateColorAlpha(0, 0, 0, 127); } } else { imagepalettecopy($new->getHandle(), $img->getHandle()); if ($img->isTransparent()) { $new->copyTransparencyFrom($img); $tc_rgb = $img->getTransparentColorRGB(); $t_color = $new->allocateColorAlpha($tc_rgb); } if ($color === null) { if ($img->isTransparent()) { $color = $t_color; } else { $color = $new->allocateColorAlpha(255, 0, 127, 127); } imagecolortransparent($new->getHandle(), $color); } } $new->fill(0, 0, $color); $x = Coordinate::fix($left, $new->getWidth(), $img->getWidth()); $y = Coordinate::fix($top, $new->getHeight(), $img->getHeight()); // blending for truecolor images if ($img->isTrueColor()) { $new->alphaBlending($merge); } // not-blending for palette images if (!$merge && !$img->isTrueColor() && isset($t_color)) { $new->getCanvas()->filledRectangle($x, $y, $x + $img->getWidth(), $y + $img->getHeight(), $t_color); } $img->copyTo($new, $x, $y); return $new; }
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()); }
/** * Returns a mapper, based on the $uri and $format * * @param string $uri File URI * @param string $format File format (extension or mime-type) or null * @return WideImage_Mapper **/ static function selectMapper($uri, $format = null) { $format = self::determineFormat($uri, $format); if (array_key_exists($format, self::$mappers)) { return self::$mappers[$format]; } $mapperClassName = 'WideImage_Mapper_' . $format; if (!class_exists($mapperClassName, false)) { $mapperFileName = WideImage::path() . 'Mapper/' . $format . '.php'; if (file_exists($mapperFileName)) { require_once $mapperFileName; } } if (class_exists($mapperClassName)) { self::$mappers[$format] = new $mapperClassName(); return self::$mappers[$format]; } throw new WideImage_UnsupportedFormatException("Format '{$format}' is not supported."); }
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 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; }
} else { $css = ''; } echo "<li><a class=\"{$css}\" href=\"?demo={$demo->name}&output={$top_form['output']->value}&colors={$top_form['ncolors']->value}&dither={$top_form['dither']->value}&match_palette={$top_form['match_palette']->value}\">{$demo->name}</a></li>\n"; } ?> </ul> <span style="font-family: Verdana, Tahoma; font-size: 11px"> This demo is primarily intended to easily try some of the features. There may be some bugs that don't actually occur with WideImage if used properly. <br /> <br /> Version: <?php echo \WideImage\WideImage::version(); ?> <br /> <br /> © 2007-2012 <br /> <a href="http://kozak.si/widethoughts/">Gasper Kozak</a><br /> <br /> Read more about WideImage on the <a href="http://wideimage.sourceforge.net">project page</a>. </span> </div> <div style="margin-left: 200px"> <?php if ($activeDemo) {
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()); }
*/ static function createTrueColorImage($width, $height) { return WideImage_TrueColorImage::create($width, $height); } /** * Check whether the given handle is a valid GD resource * * @param mixed $handle The variable to check * @return bool */ static function isValidImageHandle($handle) { return is_resource($handle) && get_resource_type($handle) == 'gd'; } /** * Throws exception if the handle isn't a valid GD resource * * @param mixed $handle The variable to check */ static function assertValidImageHandle($handle) { if (!self::isValidImageHandle($handle)) { throw new WideImage_InvalidImageHandleException("{$handle} is not a valid image handle."); } } } WideImage::checkGD(); WideImage::registerCustomMapper('WideImage_Mapper_BMP', 'image/bmp', 'bmp'); WideImage::registerCustomMapper('WideImage_Mapper_TGA', 'image/tga', 'tga');