|
użytkowników online: 67
|
OPINIE UŻYTKOWNIKÓW
|
Prawdziwa skarbnica wiedzy na temat tworzenia stron WWW i nie tylko. Korzystam z porad praktycznie codziennie, jest mi to niezbędne w mojej pracy. Sam zajmuję się tworzeniem serwisów, ale porady pisane przez Darka sa dla mnie nieocenioną pomocą! Proste, czytelne i zrozumiałe dla każdego! Czekam na więcej!
Krzysztof Szypulski
KESS - projektowanie stron
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
imagecreatefromjpeg (PHP 3 >= 3.0.16, PHP 4, PHP 5) imagecreatefromjpeg -- Create a new image from file or URL Descriptionresource imagecreatefromjpeg ( string filename )
imagecreatefromjpeg() returns an image identifier
representing the image obtained from the given filename.
imagecreatefromjpeg() returns an empty string
on failure. It also outputs an error message, which unfortunately
displays as a broken link in a browser. To ease debugging the
following example will produce an error JPEG:
Przykład 1.
Example to handle an error during creation (courtesy
vic at zymsys dot com )
|
<?php
function LoadJpeg($imgname)
{
$im = @imagecreatefromjpeg($imgname); if (!$im) { $im = imagecreate(150, 30); $bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
?>
|
|
Notatka: Obsługa JPEG jest dostępna tylko
jeśli PHP zostało skompilowane z GD-1.8 lub nowszym.
Podpowiedź: Jeśli włączona jest dyrektywa
konfiguracyjna fopen wrappers,
możliwe jest podanie jako nazwy pliku adresu URL. Zobacz opis funkcji
fopen() aby dowiedzieć się jak przekazać nazwę pliku, oraz
fopen wrappers aby uzyskać listę
obsługiwanych protokołów.
| Ostrzeżenie | PHP w
wersji starszej niż 4.3.0, pracujące pod kontrolą systemów Windows, nie
obsługują dostępu do zdalnych plików w tej funkcji, nawet jeśli opcja allow_url_fopen jest
włączona. |
User Contributed NotesKarolis Tamutis karolis.t_AT_gmail.com
31-Dec-2005 02:04
In addition to yaroukh at gmail dot com comment.
It seems that even a small image can eat up your default memory limit real quick. Config value 'memory_limit' is marked PHP_INI_ALL, so you can change it dynamically using ini_set. Therefore, we can "allocate memory dynamically", to prevent those memory limit exceeded errors.
<?php
$imageInfo = getimagesize('PATH/TO/YOUR/IMAGE');
$memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);
if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > (integer) ini_get('memory_limit') * pow(1024, 2)) {
ini_set('memory_limit', (integer) ini_get('memory_limit') + ceil(((memory_get_usage() + $memoryNeeded) - (integer) ini_get('memory_limit') * pow(1024, 2)) / pow(1024, 2)) . 'M');
}
?>
Matt with imdllc.net
14-Sep-2005 09:10
In running 4.3. Found out that jpegs generated by Canon PowerShot S70's cause imagecreatefromjpeg() to crash PHP [page cannot be displayed]. Made this function to check for it:
<?php
function check_s70($filename) {
$thereturn = false;
$handle = fopen($filename, "r");
$contents = fread($handle, 159);
fclose($handle);
if (substr($contents, 156, 3) == "S70") {
$thereturn = true;
}
return $thereturn;
}
?>
yaroukh at gmail dot com
21-Aug-2005 01:15
Estimated memory needed for ImageCreateFromJPEG
First I supposed simple width*height*bpp will be enough, it isn't though; there is some pretty big overhead.
$imageInfo = GetImageSize($imageFilename);
$memoryNeeded = Round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);
With memory_limit enabled running out of memory causes script to crash; above written will tel you how much memory you're gonna need for creating an image-resource out of image-file. So in conjunction with Memory_Get_Usage() and Get_CFG_Var('memory_limit') you can avoid the mentioned ending. (Yet there won't be too many images blocked from processing that would still fit in the memory, as the results of this are pretty accurate.)
rich at launchcode dot co dot uk
02-Aug-2005 03:54
If you get this error: "Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error" then check the JPEG files. If they are saved in CMYK format (instead of RGB) then GD will fail to load them (tested with GD 2.0.12)
elyoukey at hotmail dot com
02-Aug-2005 09:31
here is a code, inspired by the button of
tl at comvironment dot com
but here, you can make as many buttons as you need by cutting the image in as many parts as defined in the table
<?php
class Button_Array{
var $tab_button = array();var $im;function Button_Array($fileName, $tab_string){
$this -> tab_button = $tab_string;
$this -> im = $fileName;
$font = 10;
$imgFull=ImageCreateFromJPEG($this -> im);
list($width, $heightFull, $type, $attr) = getimagesize($this -> im);
$height = round($heightFull/sizeof($this->tab_button),0);
for ($i=0;$i<sizeof($this->tab_button);$i++ ) {
$pos=$i*$height;
$imgParts[$i]=ImageCreateTrueColor($width,$height);
if(imagecopy($imgParts[$i],$imgFull,0,0,0,$pos,$width,$height)){
$textColor = imagecolorallocate ($imgParts[$i],0,20,90);
ImageString ($imgParts[$i],$font,200,10,$this->tab_button[$i],$textColor);
|