コード例 #1
0
 private function GetImageObjectFromString()
 {
     $this->ImageSize = getimagesizefromstring($this->PostField);
     if ($this->ImageSize) {
         $this->ImageObject = imagecreatefromstring($this->PostField);
     }
 }
コード例 #2
0
 public function testGetImage()
 {
     $client = static::makeClient(true);
     $file = __DIR__ . "/Fixtures/files/uploadtest.png";
     $originalFilename = 'uploadtest.png';
     $mimeType = "image/png";
     $image = new UploadedFile($file, $originalFilename, $mimeType, filesize($file));
     $client->request('POST', '/api/temp_images/upload', array(), array('userfile' => $image));
     $response = json_decode($client->getResponse()->getContent());
     $property = "@id";
     $imageId = $response->image->{$property};
     $uri = $imageId . "/getImage";
     $client->request('GET', $uri);
     $this->assertEquals("image/png", $client->getResponse()->headers->get("Content-Type"));
     $imageSize = getimagesizefromstring($client->getResponse()->getContent());
     $this->assertEquals(51, $imageSize[0]);
     $this->assertEquals(23, $imageSize[1]);
     $iriConverter = $this->getContainer()->get("api.iri_converter");
     $image = $iriConverter->getItemFromIri($imageId);
     /**
      * @var $image TempImage
      */
     $this->getContainer()->get("partkeepr_image_service")->delete($image);
     $client->request('GET', $uri);
     $this->assertEquals(404, $client->getResponse()->getStatusCode());
 }
コード例 #3
0
ファイル: Guzzle5.php プロジェクト: SmartCrowd/Embed
 /**
  * {@inheritdoc}
  */
 public static function getImagesInfo(array $urls, array $config = null)
 {
     $client = isset($config['client']) ? $config['client'] : new Client(['defaults' => static::$config]);
     $result = [];
     // Build parallel requests
     $requests = [];
     foreach ($urls as $url) {
         if (strpos($url['value'], 'data:') === 0) {
             if ($info = static::getEmbeddedImageInfo($url['value'])) {
                 $result[] = array_merge($url, $info);
             }
             continue;
         }
         $requests[] = $client->createRequest('GET', $url['value']);
     }
     // Execute in parallel
     $responses = Pool::batch($client, $requests);
     // Build result set
     foreach ($responses as $i => $response) {
         if ($response instanceof RequestException) {
             continue;
         }
         if (($size = getimagesizefromstring($response->getBody())) !== false) {
             $result[] = ['width' => $size[0], 'height' => $size[1], 'size' => $size[0] * $size[1], 'mime' => $size['mime']] + $urls[$i];
         }
     }
     return $result;
 }
コード例 #4
0
ファイル: ActionController.php プロジェクト: hapn/storage
 /**
  * 上传图片
  * @throws Exception
  */
 function post_upload_action()
 {
     $redirect = false;
     if (empty($_FILES['image']['tmp_name'])) {
         if (!isset($_POST['image'])) {
             throw new Exception('hapn.u_notfound');
         }
         $content = $_POST['image'];
     } else {
         $content = file_get_contents($_FILES['image']['tmp_name']);
         $redirect = true;
     }
     if (!getimagesizefromstring($content)) {
         throw new Exception('image.u_fileIllegal');
     }
     $start = microtime(true);
     $imgApi = new StorageExport();
     $info = $imgApi->save($content);
     ksort($info);
     Logger::trace(sprintf('upload cost:%.3fms', (microtime(true) - $start) * 1000));
     if ($redirect) {
         $this->response->redirect('/image/upload?img=' . $info['img_id'] . '.' . $info['img_ext']);
     } else {
         $this->request->of = 'json';
         $this->response->setRaw(json_encode($info));
     }
 }
コード例 #5
0
 function check($files)
 {
     $result = true;
     /**
      * Check if the screenshots.png file exists.
      */
     $this->increment_check_count();
     if (!$this->file_exists($files, 'screenshot.png')) {
         $this->add_error('screenshot', "The theme doesn't include a screenshot.png file.", BaseScanner::LEVEL_BLOCKER);
         // We don't have a screenshot, so no further checks.
         return $result = false;
     }
     /**
      * We have screenshot, check the size.
      */
     $this->increment_check_count();
     $png_files = $this->filter_files($files, 'png');
     foreach ($png_files as $path => $content) {
         if ('screenshot.png' === basename($path)) {
             $image_size = getimagesizefromstring($content);
             $message = '';
             if (880 != $image_size[0]) {
                 $message .= ' The width needs to be 880 pixels.';
             }
             if (660 != $image_size[1]) {
                 $message .= ' The height needs to be 660 pixels.';
             }
             if (!empty($message)) {
                 $this->add_error('screenshot', 'The screenshot does not have the right size.' . $message, BaseScanner::LEVEL_BLOCKER);
                 $result = false;
             }
         }
     }
     return $result;
 }
コード例 #6
0
ファイル: Image.php プロジェクト: hirudy/phplib
 /**
  * 根据url获取远程图片的的基本信息
  * @param $path_url String 需要获取的图片的url地址
  * @return array|bool false-出错,否则返回基本信息数字
  */
 public static function getOnlineImageInfo($path_url)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $path_url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
     if (preg_match('/^https.*/', $path_url)) {
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
     }
     $content = curl_exec($ch);
     curl_close($ch);
     if ($content == false) {
         return false;
     }
     $info = array();
     $info['img_url'] = $path_url;
     $info['size'] = strlen($content);
     $info['md5'] = md5($content);
     $size = @getimagesizefromstring($content);
     if ($size) {
         $info['width'] = $size[0];
         $info['height'] = $size[1];
         $info['type'] = $size[2];
         $info['mime'] = $size['mime'];
     } else {
         return false;
     }
     return $info;
 }
コード例 #7
0
ファイル: GD.php プロジェクト: vakata/image
 public function __construct(string $imagedata)
 {
     if (!extension_loaded('gd') || !function_exists('gd_info')) {
         throw new ImageException('GD extension not available');
     }
     $this->data = imagecreatefromstring($imagedata);
     $this->info = getimagesizefromstring($imagedata);
 }
 /**
  * @param string $binaryImageData
  * @return mixed[]
  */
 private function getImageInfo(string $binaryImageData) : array
 {
     $imageInfo = @getimagesizefromstring($binaryImageData);
     if (false === $imageInfo) {
         throw new InvalidBinaryImageDataException('Failed to get image info.');
     }
     return $imageInfo;
 }
コード例 #9
0
ファイル: Image.php プロジェクト: zvax/imagize
 private function updateImageString($imageString)
 {
     $this->imageString = $imageString;
     $info = getimagesizefromstring($this->imageString);
     $this->width = $info[0];
     $this->height = $info[1];
     $this->type = exif_imagetype();
 }
コード例 #10
0
ファイル: PhpGd.php プロジェクト: athem/athem
 /**
  * Compatibilito override of \getimagesizefromstring() function.
  * For versions lower than php-5.4 this function does not exists, thus we must replace
  * it with \getimagesize and a stream.
  *
  * @param $string
  * @return mixed
  */
 protected function getimagesizefromstring($string)
 {
     if (function_exists('getimagesizefromstring')) {
         return getimagesizefromstring($string);
     } else {
         return getimagesize("data://plain/text;base64," . base64_encode($string));
     }
 }
コード例 #11
0
 public static function isValidImageData($imageData = null)
 {
     if (!$imageData) {
         return false;
     }
     $imageInfo = getimagesizefromstring($imageData);
     return !($imageInfo === false);
 }
コード例 #12
0
 function upload_base64($encode, $filename, $coord, $e)
 {
     $upload_dir = wp_upload_dir();
     $upload_path = str_replace('/', DIRECTORY_SEPARATOR, $upload_dir['path']) . DIRECTORY_SEPARATOR;
     $decoded = base64_decode($encode);
     $hashed_filename = md5($filename . microtime()) . '_' . $filename;
     header('Content-Type: image/png');
     //header png data sistem
     $img = imagecreatefromstring($decoded);
     //imagen string
     list($w, $h) = getimagesizefromstring($decoded);
     //obtenemos el tamaño real de la imagen
     $w_m = 800;
     // estandar
     $h_m = 600;
     // estandar
     $wm = $h * ($w_m / $h_m);
     //calculo para obtener el width general
     $hm = $w * ($h_m / $w_m);
     // calculo para obtener el height general
     $i = imagecreatetruecolor($w_m, $h_m);
     // aplicamos el rectangulo 800x600
     imagealphablending($i, FALSE);
     // obtenemos las transparencias
     imagesavealpha($i, TRUE);
     // se guarda las transparencias
     imagecopyresampled($i, $img, 0, 0, $coord->x, $coord->y - 27, $wm, $hm, $wm, $hm);
     // corta la imagen
     imagepng($i, $upload_path . $hashed_filename);
     imagedestroy($img);
     // file_put_contents($upload_path . $hashed_filename, $decoded );
     if (!function_exists('wp_handle_sideload')) {
         require_once ABSPATH . 'wp-admin/includes/file.php';
     }
     if (!function_exists('wp_get_current_user')) {
         require_once ABSPATH . 'wp-includes/pluggable.php';
     }
     if (!function_exists("wp_generate_attachment_metadata")) {
         require_once ABSPATH . 'wp-admin/includes/image.php';
     }
     if (!function_exists("wp_get_image_editor")) {
         require_once ABSPATH . 'wp-includes/media.php';
     }
     $file = array();
     $file['error'] = '';
     $file['tmp_name'] = $upload_path . $hashed_filename;
     $file['name'] = $hashed_filename;
     $file['type'] = 'image/png';
     $file['size'] = filesize($upload_path . $hashed_filename);
     $file_ = wp_handle_sideload($file, array('test_form' => false));
     $attachment = array('post_mime_type' => $file_['type'], 'post_title' => basename($filename), 'post_content' => '', 'post_status' => 'inherit');
     $attach_id = wp_insert_attachment($attachment, $file_['file']);
     $attach_data = wp_generate_attachment_metadata($attach_id, $file_['file']);
     wp_update_attachment_metadata($attach_id, $attach_data);
     //  $edit = wp_get_image_editor( $upload_path . $hashed_filename);
     // print_r($edit);
     return $attach_id;
 }
コード例 #13
0
 public function testServeResizeCrop()
 {
     //Both height and width with crop
     $url = Image::url($this->imagePath, 300, 300, array('crop' => true));
     $response = $this->call('GET', $url);
     $this->assertTrue($response->isOk());
     $sizeManipulated = getimagesizefromstring($response->getContent());
     $this->assertEquals($sizeManipulated[0], 300);
     $this->assertEquals($sizeManipulated[1], 300);
 }
 /**
  * @dataProvider frameDimensionsProvider
  */
 public function testImageIsInscribedIntoLandscapeFrame(int $frameWidth, int $frameHeight)
 {
     $imageStream = file_get_contents(__DIR__ . '/../fixture/image.jpg');
     $strategy = new GdInscribeStrategy($frameWidth, $frameHeight, 0);
     $result = $strategy->processBinaryImageData($imageStream);
     $resultImageInfo = getimagesizefromstring($result);
     $this->assertEquals($frameWidth, $resultImageInfo[0]);
     $this->assertEquals($frameHeight, $resultImageInfo[1]);
     $this->assertEquals('image/jpeg', $resultImageInfo['mime']);
 }
コード例 #15
0
ファイル: Info.php プロジェクト: bolt/filesystem
 /**
  * Creates an Info from a string of image data.
  *
  * @param string $data A string containing the image data
  *
  * @return Info
  */
 public static function createFromString($data)
 {
     $info = @getimagesizefromstring($data);
     if ($info === false) {
         throw new IOException('Failed to get image data from string');
     }
     $file = sprintf('data://%s;base64,%s', $info['mime'], base64_encode($data));
     $exif = static::readExif($file);
     return static::createFromArray($info, $exif);
 }
コード例 #16
0
ファイル: DimensionParser.php プロジェクト: innmind/crawler
 public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface
 {
     $start = $this->clock->now();
     if (!$this->isImage($attributes)) {
         return $attributes;
     }
     $infos = getimagesizefromstring((string) $response->body());
     $time = $this->clock->now()->elapsedSince($start)->milliseconds();
     return $attributes->put(self::key(), new Attributes(self::key(), (new Map('string', AttributeInterface::class))->put('width', new Attribute('width', $infos[0], $time))->put('height', new Attribute('height', $infos[1], $time))));
 }
 public function testImageIsResizedToGivenDimensions()
 {
     $width = 15;
     $height = 10;
     $imageStream = file_get_contents(__DIR__ . '/../fixture/image.jpg');
     $result = (new ImageMagickResizeStrategy($width, $height))->processBinaryImageData($imageStream);
     $resultImageInfo = getimagesizefromstring($result);
     $this->assertEquals($width, $resultImageInfo[0]);
     $this->assertEquals($height, $resultImageInfo[1]);
     $this->assertEquals('image/jpeg', $resultImageInfo['mime']);
 }
コード例 #18
0
ファイル: UtilsTrait.php プロジェクト: SmartCrowd/Embed
 /**
  * Extract image info from embedded images (data:image/jpeg;base64,...).
  * 
  * @param string $content
  * 
  * @return array|false
  */
 protected static function getEmbeddedImageInfo($content)
 {
     $pieces = explode(';', $content, 2);
     if (count($pieces) !== 2 || strpos($pieces[0], 'image/') === false || strpos($pieces[1], 'base64,') !== 0) {
         return false;
     }
     if (($info = getimagesizefromstring(base64_decode(substr($pieces[1], 7)))) !== false) {
         return ['width' => $info[0], 'height' => $info[1], 'size' => $info[0] * $info[1], 'mime' => $info['mime']];
     }
     return false;
 }
コード例 #19
0
ファイル: Base64.php プロジェクト: phpoffice/phppowerpoint
 /**
  * @return string
  */
 public function getMimeType()
 {
     $sImage = $this->getContents();
     if (!function_exists('getimagesizefromstring')) {
         $uri = 'data://application/octet-stream;base64,' . base64_encode($sImage);
         $image = getimagesize($uri);
     } else {
         $image = getimagesizefromstring($sImage);
     }
     return image_type_to_mime_type($image[2]);
 }
コード例 #20
0
ファイル: Thumbnail.php プロジェクト: rammstein4o/kanboard
 /**
  * Load the image blob in memory with GD
  *
  * @access public
  * @param  string $blob
  * @return Thumbnail
  */
 public function fromString($blob)
 {
     if (!function_exists('getimagesizefromstring')) {
         $uri = 'data://application/octet-stream;base64,' . base64_encode($blob);
         $this->metadata = getimagesize($uri);
     } else {
         $this->metadata = getimagesizefromstring($blob);
     }
     $this->srcImage = imagecreatefromstring($blob);
     return $this;
 }
コード例 #21
0
 protected function runInternal()
 {
     $imageContent = file_get_contents($this->filePath);
     list($originalWidth, $originalHeight) = getimagesizefromstring($imageContent);
     // Check if crop is smaller or equal than original image
     $isCropSizeCorrect = $originalWidth >= $this->width && $originalHeight >= $this->height;
     // Check if crop offset doesn't exceed original image
     $isCropOffsetCorrect = $this->offsetX < $originalWidth && $this->offsetY < $originalHeight;
     // Leaving image intact when crop sizes or offsets are incorrect
     if (!$isCropSizeCorrect || !$isCropOffsetCorrect) {
         $this->width = $originalWidth;
         $this->height = $originalHeight;
         return;
     }
     $bool = true;
     $src = imagecreatefromstring($imageContent);
     $extension = pathinfo($this->filePath, PATHINFO_EXTENSION);
     // Auto-rotate
     if ($extension === 'jpg' || $extension === 'jpeg') {
         try {
             $exif = exif_read_data($this->filePath);
         } catch (\Exception $e) {
         }
         if (!empty($exif['Orientation'])) {
             switch ($exif['Orientation']) {
                 case 3:
                     $src = imagerotate($src, 180, 0);
                     break;
                 case 6:
                     $src = imagerotate($src, -90, 0);
                     break;
                 case 8:
                     $src = imagerotate($src, 90, 0);
                     break;
             }
         }
     }
     // Create blank image
     $dst = ImageCreateTrueColor($this->width, $this->height);
     if ($extension === 'png') {
         $bool = $bool && imagesavealpha($dst, true) && imagealphablending($dst, false);
     }
     // Place, resize and save file
     $bool = $bool && imagecopyresampled($dst, $src, 0, 0, $this->offsetX, $this->offsetY, $this->width, $this->height, $this->width, $this->height);
     $bool && $extension === 'png' ? imagepng($dst, $this->filePath) : imagejpeg($dst, $this->filePath, $this->thumbQuality);
     // Clean
     if ($src) {
         imagedestroy($src);
     }
     if ($dst) {
         imagedestroy($dst);
     }
 }
コード例 #22
0
 protected function runInternal()
 {
     $imageContent = file_get_contents($this->filePath);
     // New size
     list($originalWidth, $originalHeight) = getimagesizefromstring($imageContent);
     $scale = $this->isFit ? min($this->width / $originalWidth, $this->height / $originalHeight) : max($this->width / $originalWidth, $this->height / $originalHeight);
     $this->width = max(1, (int) floor($originalWidth * $scale));
     $this->height = max(1, (int) floor($originalHeight * $scale));
     // Check need resize
     if ($scale >= 1) {
         $this->width = $originalWidth;
         $this->height = $originalHeight;
         return;
     }
     $bool = true;
     $src = imagecreatefromstring($imageContent);
     $extension = pathinfo($this->filePath, PATHINFO_EXTENSION);
     // Auto-rotate
     if ($extension === 'jpg' || $extension === 'jpeg') {
         try {
             $exif = exif_read_data($this->filePath);
         } catch (\Exception $e) {
         }
         if (!empty($exif['Orientation'])) {
             switch ($exif['Orientation']) {
                 case 3:
                     $src = imagerotate($src, 180, 0);
                     break;
                 case 6:
                     $src = imagerotate($src, -90, 0);
                     break;
                 case 8:
                     $src = imagerotate($src, 90, 0);
                     break;
             }
         }
     }
     // Create blank image
     $dst = ImageCreateTrueColor($this->width, $this->height);
     if ($extension === 'png') {
         $bool = $bool && imagesavealpha($dst, true) && imagealphablending($dst, false);
     }
     // Place, resize and save file
     $bool = $bool && imagecopyresampled($dst, $src, 0, 0, 0, 0, $this->width, $this->height, $originalWidth, $originalHeight);
     $bool && $extension === 'png' ? imagepng($dst, $this->filePath) : imagejpeg($dst, $this->filePath, $this->thumbQuality);
     // Clean
     if ($src) {
         imagedestroy($src);
     }
     if ($dst) {
         imagedestroy($dst);
     }
 }
コード例 #23
0
 public function onCreateFileImageThumbnailSource(File $file, &$imgPath, $media = null)
 {
     // If we are on a private node, we won't do any remote calls (just as a precaution until
     // we can configure this from config.php for the private nodes)
     if (common_config('site', 'private')) {
         return true;
     }
     if ($media !== 'image') {
         return true;
     }
     // If there is a local filename, it is either a local file already or has already been downloaded.
     if (!empty($file->filename)) {
         return true;
     }
     $this->checkWhitelist($file->getUrl());
     // First we download the file to memory and test whether it's actually an image file
     $imgData = HTTPClient::quickGet($file->getUrl());
     common_debug(sprintf('Downloading remote file id==%u with URL: %s', $file->id, $file->getUrl()));
     $info = @getimagesizefromstring($imgData);
     if ($info === false) {
         throw new UnsupportedMediaException(_('Remote file format was not identified as an image.'), $file->getUrl());
     } elseif (!$info[0] || !$info[1]) {
         throw new UnsupportedMediaException(_('Image file had impossible geometry (0 width or height)'));
     }
     $filehash = hash(File::FILEHASH_ALG, $imgData);
     try {
         // Exception will be thrown before $file is set to anything, so old $file value will be kept
         $file = File::getByHash($filehash);
         //FIXME: Add some code so we don't have to store duplicate File rows for same hash files.
     } catch (NoResultException $e) {
         $filename = $filehash . '.' . common_supported_mime_to_ext($info['mime']);
         $fullpath = File::path($filename);
         // Write the file to disk if it doesn't exist yet. Throw Exception on failure.
         if (!file_exists($fullpath) && file_put_contents($fullpath, $imgData) === false) {
             throw new ServerException(_('Could not write downloaded file to disk.'));
         }
         // Updated our database for the file record
         $orig = clone $file;
         $file->filehash = $filehash;
         $file->filename = $filename;
         $file->width = $info[0];
         // array indexes documented on php.net:
         $file->height = $info[1];
         // https://php.net/manual/en/function.getimagesize.php
         // Throws exception on failure.
         $file->updateWithKeys($orig, 'id');
     }
     // Get rid of the file from memory
     unset($imgData);
     $imgPath = $file->getPath();
     return false;
 }
コード例 #24
0
ファイル: Books.php プロジェクト: aekkapun/yii2-mylib
 /**
  * resamples image to match boundary limits by width. Height is not checked and will resampled according to width's change percentage
  *
  * @param string $img_blob image source as blob string
  * @param int $max_width max allowed width for picture in pixels
  * 
  * @return string image as string BLOB
  */
 public static function getResampledImageByWidthAsBlob($img_blob, $max_width = 800)
 {
     list($src_w, $src_h) = getimagesizefromstring($img_blob);
     $src_image = imagecreatefromstring($img_blob);
     $dst_w = $src_w > $max_width ? $max_width : $src_w;
     $dst_h = $src_w > $max_width ? $max_width / $src_w * $src_h : $src_h;
     //minimize height in percent to width
     $dst_image = imagecreatetruecolor($dst_w, $dst_h);
     imagecopyresized($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
     ob_start();
     imagejpeg($dst_image);
     return ob_get_clean();
 }
コード例 #25
0
ファイル: ImageValidator.php プロジェクト: shtormus/examples
 public function validateValue($value)
 {
     if (false === ($imageInfo = getimagesizefromstring($value))) {
         return [$this->notImage, []];
     }
     if (!in_array($imageInfo[2], $this->imageTypes)) {
         return [$this->wrongImageType, []];
     }
     if (mb_strlen($value, '8bit') > $this->maxSize) {
         return [$this->tooBig, ['limit' => $this->maxSize, 'formattedLimit' => Yii::$app->formatter->asShortSize($this->maxSize)]];
     }
     return null;
 }
コード例 #26
0
 public function imageProvider() : array
 {
     return [['image/png', function () : string {
         $image = imagecreatetruecolor(1000, 1000);
         ob_start();
         imagepng($image);
         imagedestroy($image);
         return ob_get_clean();
     }, function (string $output) {
         $image = imagecreatefromstring($output);
         $imageSize = getimagesizefromstring($output);
         $this->assertSame(1000, $imageSize[0]);
         $this->assertSame(1000, $imageSize[1]);
         $this->assertSame('image/png', $imageSize['mime']);
         $color = imagecolorsforindex($image, imagecolorat($image, 999, 999));
         $this->assertSame(0, $color['red']);
         $this->assertSame(0, $color['green']);
         $this->assertSame(0, $color['blue']);
     }], ['image/jpeg', function () : string {
         return file_get_contents(__DIR__ . '/../resources/exif.jpg');
     }, function (string $output) {
         $image = imagecreatefromstring($output);
         $imageSize = getimagesizefromstring($output);
         $this->assertSame(1001, $imageSize[0]);
         $this->assertSame(1001, $imageSize[1]);
         $this->assertSame('image/jpeg', $imageSize['mime']);
         $color = imagecolorsforindex($image, imagecolorat($image, 999, 999));
         $this->assertSame(0, $color['red']);
         $this->assertSame(0, $color['green']);
         $this->assertSame(0, $color['blue']);
         $fp = tmpfile();
         fwrite($fp, $output);
         $this->assertArrayNotHasKey('UserComment', exif_read_data(stream_get_meta_data($fp)['uri']));
     }, [LogLevel::ERROR, LogLevel::WARNING, LogLevel::WARNING]], ['image/svg+xml', function () : string {
         return '<?xml version="1.0" ?>
                 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                     <a xlink:href="https://example.com/">
                         <rect width="1000" height="1000" />
                     </a>
                 </svg>';
     }, function (string $output) {
         $svgValidatorTest = new SVGValidatorTest();
         $this->assertEquals($svgValidatorTest->formatXML('<?xml version="1.0" ?>
                     <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                         <a>
                             <rect width="1000" height="1000" />
                         </a>
                     </svg>
                 '), $svgValidatorTest->formatXML($output));
     }, [LogLevel::ERROR]]];
 }
コード例 #27
0
ファイル: QrCodeTest.php プロジェクト: okhvedkovich/qrcode
 public function testQrCodeImageSize()
 {
     $width = 500;
     $height = 500;
     $imageTestData = $this->_getTestImageData();
     $qrCode = new QrCode('test', $width, $height);
     // Create a stub for the SomeClass class.
     $renderer = $this->_createGoogleRendererMock($imageTestData);
     /** @var $renderer QrCode\Contract\RendererInterface */
     $qrCode->setRenderer($renderer);
     $imageData = getimagesizefromstring($qrCode->generate());
     $this->assertEquals($imageData[0], $width);
     $this->assertEquals($imageData[1], $height);
 }
コード例 #28
0
function ShowAllImageInZip($path, $filename)
{
    ignore_user_abort(true);
    set_time_limit(0);
    // disable the time limit for this script
    $dl_file = $filename;
    $fullPath = $path . $dl_file;
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
        case "zip":
            break;
        default:
            exit;
    }
    //echo "this is zip ok <br/>";
    $zip = new ZipArchive();
    if ($zip->open($fullPath) === true) {
        for ($i = 0; $i < $zip->numFiles; $i++) {
            //$zip->extractTo('path/to/extraction/', array($zip->getNameIndex($i)));
            // here you can run a custom function for the particular extracted file
            $cont_name = $zip->getNameIndex($i);
            $cont_path_parts = pathinfo($cont_name);
            $cont_ext = strtolower($cont_path_parts["extension"]);
            if ($cont_ext == "jpg") {
                $contents = '';
                //echo $cont_name."<br/>";
                $fp = $zip->getStream($cont_name);
                if (!$fp) {
                    exit("failed\n");
                }
                //echo "get stream...<br/>";
                while (!feof($fp)) {
                    $contents .= fread($fp, 2);
                }
                fclose($fp);
                $b64 = base64_encode($contents);
                list($w, $h) = getimagesizefromstring($contents);
                //echo $w." ".$h."<br/>";
                list($width, $height) = fixWidth(600, $w, $h);
                //echo $width." ".$height."<br/>";
                echo "<img src='data:image/jpeg;base64,{$b64}' width='" . $width . "' height='" . $height . "'><br/>";
            }
        }
        $zip->close();
    } else {
        echo "fail open file " . $filename . "<br/>";
    }
}
コード例 #29
0
ファイル: ZipFile.php プロジェクト: phpoffice/phppowerpoint
 /**
  * @return string
  */
 public function getMimeType()
 {
     if (!CommonFile::fileExists($this->getZipFileOut())) {
         throw new \Exception('File ' . $this->getZipFileOut() . ' does not exist');
     }
     $oArchive = new \ZipArchive();
     $oArchive->open($this->getZipFileOut());
     if (!function_exists('getimagesizefromstring')) {
         $uri = 'data://application/octet-stream;base64,' . base64_encode($oArchive->getFromName($this->getZipFileIn()));
         $image = getimagesize($uri);
     } else {
         $image = getimagesizefromstring($oArchive->getFromName($this->getZipFileIn()));
     }
     return image_type_to_mime_type($image[2]);
 }
コード例 #30
0
 /**
  * @param ResourceInterface $resource
  * @param GaufretteFile $file
  * @throws \InvalidArgumentException|\UnexpectedValueException|FileNotFound
  */
 public function updateResourceMetadata(ResourceInterface $resource, GaufretteFile $file)
 {
     if ($resource instanceof Document) {
         $mimeType = $file->getMimeType();
         if (!$mimeType) {
             $finfo = new \finfo(FILEINFO_MIME_TYPE);
             $mimeType = $finfo->buffer($file->getContent());
         }
         $resource->setFileModifiedAt($file->getMtime())->setFileSize($file->getSize())->setFileType($mimeType);
     }
     if ($resource instanceof Image) {
         $imageSize = getimagesizefromstring($file->getContent());
         $resource->setWidth(isset($imageSize[0]) ? $imageSize[0] : null)->setHeight(isset($imageSize[1]) ? $imageSize[1] : null);
     }
 }