Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 67
W CZYM MOGĘ POMÓC?


   
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

   
GALERIA FOTOGRAFII
   
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

Description

resource 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); /* Attempt to open */
  
if (!$im) { /* See if it failed */
      
$im  = imagecreate(150, 30); /* Create a blank image */
      
$bgc = imagecolorallocate($im, 255, 255, 255);
      
$tc  = imagecolorallocate($im, 0, 0, 0);
      
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
      
/* Output an errmsg */
      
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 Notes

Karolis 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();// the text of each button you want to create
  
var $im;//the image file
  
  
function Button_Array($fileName, $tab_string){
      
$this -> tab_button = $tab_string;
      
$this -> im = $fileName;
      
      
//parameters
      
$font  = 10;

      
//cut the full image in X parts
       //X = the number of buttons you want
        
$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)){
          
              
//manips
              
$textColor = imagecolorallocate ($imgParts[$i],0,20,90);   
              
ImageString ($imgParts[$i],$font,200,10,$this->tab_button[$i],$textColor);
              
              
//cr

 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt