本文整理汇总了PHP中getimagesizefromstring函数的典型用法代码示例。如果您正苦于以下问题:PHP getimagesizefromstring函数的具体用法?PHP getimagesizefromstring怎么用?PHP getimagesizefromstring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getimagesizefromstring函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetImageObjectFromString
private function GetImageObjectFromString()
{
$this->ImageSize = getimagesizefromstring($this->PostField);
if ($this->ImageSize) {
$this->ImageObject = imagecreatefromstring($this->PostField);
}
}
示例2: testGetImage
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: getImagesInfo
/**
* {@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: post_upload_action
/**
* 上传图片
* @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: check
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: getOnlineImageInfo
/**
* 根据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: __construct
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);
}
示例8: getImageInfo
/**
* @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: updateImageString
private function updateImageString($imageString)
{
$this->imageString = $imageString;
$info = getimagesizefromstring($this->imageString);
$this->width = $info[0];
$this->height = $info[1];
$this->type = exif_imagetype();
}
示例10: getimagesizefromstring
/**
* 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: isValidImageData
public static function isValidImageData($imageData = null)
{
if (!$imageData) {
return false;
}
$imageInfo = getimagesizefromstring($imageData);
return !($imageInfo === false);
}
示例12: upload_base64
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: testServeResizeCrop
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);
}
示例14: testImageIsInscribedIntoLandscapeFrame
/**
* @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: createFromString
/**
* 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);
}