PHP.mk документација

imagecreatefromstring

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.imagecreatefromstring.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.imagecreatefromstring.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
imagecreatefromstring

Референца за `function.imagecreatefromstring.php` со подобрена типографија и навигација.

function.imagecreatefromstring.php

imagecreatefromstring

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

imagecreatefromstringСоздај нова слика од стримот на сликата во низата

= NULL

imagecreatefromstring(string $data): GdImage|false

imagecreatefromstring() враќа идентификатор на слика што ја претставува сликата добиена од дадената data. Овие типови ќе бидат автоматски откриени ако вашата верзија на PHP ги поддржува: JPEG, PNG, GIF, BMP, WBMP, GD2, WEBP и AVIF.

Параметри

data

Низа што ја содржи сликата.

Вратени вредности

Објект со слика ќе биде вратен при успех. false се враќа ако типот на сликата не е поддржан, податоците не се во препознатлив формат, или сликата е оштетена и не може да се вчита.

Errors/Exceptions

imagecreatefromstring() крева грешка на ниво E_WARNING, ако податоците не се во препознатлив формат.

Дневник на промени

Верзија = NULL
8.0.0 При успех, оваа функција враќа GDImage инстанца сега; претходно, а resource .
7.3.0 WEBP сега е поддржано (ако е поддржано од libgd во употреба).

Примери

Пример #1 imagecreatefromstring() example

<?php
$data
= 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);

$im = imagecreatefromstring($data);
if (
$im !== false) {
header('Content-Type: image/png');
imagepng($im);
}
else {
echo
'An error occurred.';
}
?>

Горниот пример ќе прикаже нешто слично на:

Output of example : imagecreatefromstring()

Види Исто така

Белешки од корисници Управување со PDO конекции

виле дот јангман ат џимејл дот ком
пред 17 години
While downloading images from internet, it's easiest to let php decide what is the file type. So, forget using imagecreatefromjpg, imagecreatefromgif and imagecreatefrompng. Instead, this is the way to go:

<?php
$src = "http://www.varuste.net/tiedostot/l_ylabanneri.jpg";
$image = imagecreatefromstring(file_get_contents($src));
?>
php dot net на phor dot net
пред 16 години
My site allows anonymous uploads to a web-accessible location (that will execute a script if it finds one).

Naturally, I need to verify that only harmless content is accepted. I am expecting only images, so I use:

<?php
  $im = $imagecreatefromstring($USERFILE);
  $valid = ($im != FALSE);
  imagedestroy($im);
  return $valid;
?>
анон ат дуд дот ком
пред 10 години
[Editor's note: BMP will be supported as of PHP 7.2.0.]

In case it's not obvious from the lack of "imagecreatefrombmp()" in GD, this function cannot handle plain old BMP files either.
крис ат хејденвилер дот ком
пред 6 години
imagecreatefromstring does not appear to support WebP images (tested on PHP 7.2.10, with GD 2.1.0 and GD WebP support enabled)
логан ат логансбејли дот ком
пред 16 години
So you guys don't spend an hour trying to figure out why your script keeps running out of memory when you're using this or the other imagecreatefrom functions.  GD uncompresses the image when you use these functions, and this can lead to your script running out of memory.

If you download a rawimage save it on your computer to jpeg so the file size comes down, GD will automatically convert it to the raw and you can possibly run out of memory.
хоуп ат ит-хелпс дот ком
пред 14 години
Create an image resource from file, without knowing image type:

<?php
function imagecreatefromfile($imagepath=false) {
    if(!$imagepath || !$is_readable($imagepath) return false;
    return @imagecreatefromstring(file_get_contents($imagepath));
}
$img_resource=imagecreatefromfile($imagepath);
?>
Artur Graniszewski
пред 18 години
I use dynamically generated images that require a little touch-up before being displayed. So essentially I do some base work, then store the images in a memory cache (APC), reload the images again from the cache later on "into" GD, do final processing and then display the image. 
Since I wanted to avoid a lot of disc access I used the output buffering functions:

<?php
   // Do your image processing stuff
   
   // Start buffering
   ob_start ( );
   ImageGD ( $hImage );
   $sImage = ob_get_contents ( );
   ob_end_clean ( );

   // Put stuff into cache
 
   // Reload from cache and recreate image
   $hImage = imagecreatefromstring ( $sImage );

   // Do final editing stuff and output image
?>

Of course this is a condensed example but I just wanted to share the idea.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.