Re: [PHP] [GD] Image errors

2009-07-15 Thread Peter Ford
Ash, Martin,

Seems you are both wandering around the obvious problem...

I suspect that $tipo (in the next line) is *supposed* to be $type - sounds like
a partial Italian translation to me...

So given that $type=imagecreatefrompng (for example, if the mime check returns
'png' - not very reliable, I suspect),

then

$immagine = $type($this-updir.$id.'.png')

should create a GD resource from the file, but the image appears to be empty.

My take on this is:

OP says he gets the same result from
$immagine = imagecreatefromjpeg(this-updir.$id.'.png')

- well I might expect to get an error message if I loaded a PNG expecting it to
be a JPEG, but I certainly wouldn't expect an image.

On some basic tests, I find that mime_content_type() is not defined on my
system, so ignoring that and trying to load a PNG file using imagecreatefromjpeg
results in pretty much the same result as the OP...

Conclusions:

First: if you use Italian for your variable names, don't change half of their
instances to English...

Second: Make sure you actually know the mime type of a file before you try to
load it into GD...

My version of this would test against known image types to try the GD function:

foreach (Array('png','jpeg','gif') as $typeName)
{
  $type = 'imagecreatefrom'.$typeName;
  $immagine = $type(this-updir.$id.'.png'le);
  if (is_resource($immagine))
  {
header('Content-type: image/jpeg');
imagejpeg($immagine,null,100);
imagedestroy($immagine);
break;
  }
}
header('HTTP/1.0 500 File is not an allowed image type');





-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] [GD] Image errors

2009-07-15 Thread Peter Ford
Martin Scotta wrote:
 Why are you ussing GD?
 All you need is output the image to the browser?
 
 try this... I didn't test/run this code, but it may work...
 
 public function showPicture( $id ) {
   header('Content-type:' . mime_content_type( $this-updir . $id .
 '.png' ) );
   readfile( $this-updir . $id . '.png' );
   }
 
 hey, look, just 2 lines!
 
But it doesn't convert the image from whatever came in to a JPEG output, which
is what the OP's code appears to be trying to do (and possibly ought to work...)



-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] [GD] Image errors

2009-07-14 Thread Martin Scotta
$immagine = $tipo($this-updir.$id.'.png');

$tipo is undefined


On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino
volantetuxs...@codeinside.it wrote:
 Hi to all

 I get a problem processing an image with GD libraries.

 This is my function

   public function showPicture($id) {
       header('Content-type: image/jpeg');
       $mime = mime_content_type($this-updir.$id.'.png');
       $type = explode('/',$mime);
       $type = 'imagecreatefrom'.$type[1];
       $immagine = $tipo($this-updir.$id.'.png');
       imagejpeg($immagine,null,100);
       imagedestroy($immagine);
   }

 If i commentize the header function i get a lot of strange simbols (such
 as the code of a jpeg image!) but no errors.
 The result of this code is a blank page. In Firefox the title sets to
 picture.php (JPEG image) and if i right-click it and click on
 Proprieties i get 0px × 0px (resized as 315px × 19px).

 P.S.: I get the same result when I write $immagine =
 imagecreatefromjpeg(...)

 (Sorry for my english)

 Thanks in advance,
 Alfio.

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
Martin Scotta

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] [GD] Image errors

2009-07-14 Thread Ashley Sheridan
On Tue, 2009-07-14 at 13:27 -0300, Martin Scotta wrote:
 $immagine = $tipo($this-updir.$id.'.png');
 
 $tipo is undefined
 
 
 On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino
 volantetuxs...@codeinside.it wrote:
  Hi to all
 
  I get a problem processing an image with GD libraries.
 
  This is my function
 
public function showPicture($id) {
header('Content-type: image/jpeg');
$mime = mime_content_type($this-updir.$id.'.png');
$type = explode('/',$mime);
$type = 'imagecreatefrom'.$type[1];
$immagine = $tipo($this-updir.$id.'.png');
imagejpeg($immagine,null,100);
imagedestroy($immagine);
}
 
  If i commentize the header function i get a lot of strange simbols (such
  as the code of a jpeg image!) but no errors.
  The result of this code is a blank page. In Firefox the title sets to
  picture.php (JPEG image) and if i right-click it and click on
  Proprieties i get 0px × 0px (resized as 315px × 19px).
 
  P.S.: I get the same result when I write $immagine =
  imagecreatefromjpeg(...)
 
  (Sorry for my english)
 
  Thanks in advance,
  Alfio.
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 
 -- 
 Martin Scotta
 
Also, it doesn't look like you're actually doing anything with $type

Thanks
Ash
www.ashleysheridan.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] [GD] Image errors

2009-07-14 Thread Martin Scotta
He is calling the function by variable

something like this

$func = 'var_dump';

$func( new Foo );

On Tue, Jul 14, 2009 at 1:30 PM, Ashley
Sheridana...@ashleysheridan.co.uk wrote:
 On Tue, 2009-07-14 at 13:27 -0300, Martin Scotta wrote:
 $immagine = $tipo($this-updir.$id.'.png');

 $tipo is undefined


 On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino
 volantetuxs...@codeinside.it wrote:
  Hi to all
 
  I get a problem processing an image with GD libraries.
 
  This is my function
 
    public function showPicture($id) {
        header('Content-type: image/jpeg');
        $mime = mime_content_type($this-updir.$id.'.png');
        $type = explode('/',$mime);
        $type = 'imagecreatefrom'.$type[1];
        $immagine = $tipo($this-updir.$id.'.png');
        imagejpeg($immagine,null,100);
        imagedestroy($immagine);
    }
 
  If i commentize the header function i get a lot of strange simbols (such
  as the code of a jpeg image!) but no errors.
  The result of this code is a blank page. In Firefox the title sets to
  picture.php (JPEG image) and if i right-click it and click on
  Proprieties i get 0px × 0px (resized as 315px × 19px).
 
  P.S.: I get the same result when I write $immagine =
  imagecreatefromjpeg(...)
 
  (Sorry for my english)
 
  Thanks in advance,
  Alfio.
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 



 --
 Martin Scotta

 Also, it doesn't look like you're actually doing anything with $type

 Thanks
 Ash
 www.ashleysheridan.co.uk





-- 
Martin Scotta

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] [GD] Image errors

2009-07-14 Thread Ashley Sheridan
On Tue, 2009-07-14 at 13:41 -0300, Martin Scotta wrote:
 He is calling the function by variable
 
 something like this
 
 $func = 'var_dump';
 
 $func( new Foo );
 
 On Tue, Jul 14, 2009 at 1:30 PM, Ashley
 Sheridana...@ashleysheridan.co.uk wrote:
  On Tue, 2009-07-14 at 13:27 -0300, Martin Scotta wrote:
  $immagine = $tipo($this-updir.$id.'.png');
 
  $tipo is undefined
 
 
  On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino
  volantetuxs...@codeinside.it wrote:
   Hi to all
  
   I get a problem processing an image with GD libraries.
  
   This is my function
  
 public function showPicture($id) {
 header('Content-type: image/jpeg');
 $mime = mime_content_type($this-updir.$id.'.png');
 $type = explode('/',$mime);
 $type = 'imagecreatefrom'.$type[1];
 $immagine = $tipo($this-updir.$id.'.png');
 imagejpeg($immagine,null,100);
 imagedestroy($immagine);
 }
  
   If i commentize the header function i get a lot of strange simbols 
   (such
   as the code of a jpeg image!) but no errors.
   The result of this code is a blank page. In Firefox the title sets to
   picture.php (JPEG image) and if i right-click it and click on
   Proprieties i get 0px × 0px (resized as 315px × 19px).
  
   P.S.: I get the same result when I write $immagine =
   imagecreatefromjpeg(...)
  
   (Sorry for my english)
  
   Thanks in advance,
   Alfio.
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
 
 
 
  --
  Martin Scotta
 
  Also, it doesn't look like you're actually doing anything with $type
 
  Thanks
  Ash
  www.ashleysheridan.co.uk
 
 
 
 
 
 -- 
 Martin Scotta
 

Bottom post ;)

$type = explode('/',$mime);
$type = 'imagecreatefrom'.$type[1];

$immagine = $tipo($this-updir.$id.'.png');
imagejpeg($immagine,null,100);
imagedestroy($immagine);

I'm not sure you understood what I meant. line 2 above $type is assigned
to the string 'imagecreatefrom'.$type[1];

Now I assume that was to be used later in some sort of eval() statement,
but its never called again, so the line really does nothing.

Thanks
Ash
www.ashleysheridan.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] [GD] Image errors

2009-07-14 Thread Martin Scotta
On Tue, Jul 14, 2009 at 1:48 PM, Ashley
Sheridana...@ashleysheridan.co.uk wrote:
 On Tue, 2009-07-14 at 13:41 -0300, Martin Scotta wrote:
 He is calling the function by variable

 something like this

 $func = 'var_dump';

 $func( new Foo );

 On Tue, Jul 14, 2009 at 1:30 PM, Ashley
 Sheridana...@ashleysheridan.co.uk wrote:
  On Tue, 2009-07-14 at 13:27 -0300, Martin Scotta wrote:
  $immagine = $tipo($this-updir.$id.'.png');
 
  $tipo is undefined
 
 
  On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino
  volantetuxs...@codeinside.it wrote:
   Hi to all
  
   I get a problem processing an image with GD libraries.
  
   This is my function
  
     public function showPicture($id) {
         header('Content-type: image/jpeg');
         $mime = mime_content_type($this-updir.$id.'.png');
         $type = explode('/',$mime);
         $type = 'imagecreatefrom'.$type[1];
         $immagine = $tipo($this-updir.$id.'.png');
         imagejpeg($immagine,null,100);
         imagedestroy($immagine);
     }
  
   If i commentize the header function i get a lot of strange simbols 
   (such
   as the code of a jpeg image!) but no errors.
   The result of this code is a blank page. In Firefox the title sets to
   picture.php (JPEG image) and if i right-click it and click on
   Proprieties i get 0px × 0px (resized as 315px × 19px).
  
   P.S.: I get the same result when I write $immagine =
   imagecreatefromjpeg(...)
  
   (Sorry for my english)
  
   Thanks in advance,
   Alfio.
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
 
 
 
  --
  Martin Scotta
 
  Also, it doesn't look like you're actually doing anything with $type
 
  Thanks
  Ash
  www.ashleysheridan.co.uk
 
 



 --
 Martin Scotta


 Bottom post ;)

 $type = explode('/',$mime);
 $type = 'imagecreatefrom'.$type[1];

 $immagine = $tipo($this-updir.$id.'.png');
 imagejpeg($immagine,null,100);
 imagedestroy($immagine);

 I'm not sure you understood what I meant. line 2 above $type is assigned
 to the string 'imagecreatefrom'.$type[1];

 Now I assume that was to be used later in some sort of eval() statement,
 but its never called again, so the line really does nothing.

 Thanks
 Ash
 www.ashleysheridan.co.uk



Mmmm, No

$type = explode('/',$mime); # type is array
$type = 'imagecreatefrom'.$type[1]; # type is a string

He is actually re-assigning the var ussing the content of the var.
Sounds crazy, but I use this method a lot, it helps to keep the scope clean.

-- 
Martin Scotta
ps. tipo is type in Spanish

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] [GD] Image errors

2009-07-14 Thread Ashley Sheridan
On Tue, 2009-07-14 at 14:16 -0300, Martin Scotta wrote:
 On Tue, Jul 14, 2009 at 1:48 PM, Ashley
 Sheridana...@ashleysheridan.co.uk wrote:
  On Tue, 2009-07-14 at 13:41 -0300, Martin Scotta wrote:
  He is calling the function by variable
 
  something like this
 
  $func = 'var_dump';
 
  $func( new Foo );
 
  On Tue, Jul 14, 2009 at 1:30 PM, Ashley
  Sheridana...@ashleysheridan.co.uk wrote:
   On Tue, 2009-07-14 at 13:27 -0300, Martin Scotta wrote:
   $immagine = $tipo($this-updir.$id.'.png');
  
   $tipo is undefined
  
  
   On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino
   volantetuxs...@codeinside.it wrote:
Hi to all
   
I get a problem processing an image with GD libraries.
   
This is my function
   
  public function showPicture($id) {
  header('Content-type: image/jpeg');
  $mime = mime_content_type($this-updir.$id.'.png');
  $type = explode('/',$mime);
  $type = 'imagecreatefrom'.$type[1];
  $immagine = $tipo($this-updir.$id.'.png');
  imagejpeg($immagine,null,100);
  imagedestroy($immagine);
  }
   
If i commentize the header function i get a lot of strange simbols 
(such
as the code of a jpeg image!) but no errors.
The result of this code is a blank page. In Firefox the title sets to
picture.php (JPEG image) and if i right-click it and click on
Proprieties i get 0px × 0px (resized as 315px × 19px).
   
P.S.: I get the same result when I write $immagine =
imagecreatefromjpeg(...)
   
(Sorry for my english)
   
Thanks in advance,
Alfio.
   
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
   
   
  
  
  
   --
   Martin Scotta
  
   Also, it doesn't look like you're actually doing anything with $type
  
   Thanks
   Ash
   www.ashleysheridan.co.uk
  
  
 
 
 
  --
  Martin Scotta
 
 
  Bottom post ;)
 
  $type = explode('/',$mime);
  $type = 'imagecreatefrom'.$type[1];
 
  $immagine = $tipo($this-updir.$id.'.png');
  imagejpeg($immagine,null,100);
  imagedestroy($immagine);
 
  I'm not sure you understood what I meant. line 2 above $type is assigned
  to the string 'imagecreatefrom'.$type[1];
 
  Now I assume that was to be used later in some sort of eval() statement,
  but its never called again, so the line really does nothing.
 
  Thanks
  Ash
  www.ashleysheridan.co.uk
 
 
 
 Mmmm, No
 
 $type = explode('/',$mime); # type is array
 $type = 'imagecreatefrom'.$type[1]; # type is a string
 
 He is actually re-assigning the var ussing the content of the var.
 Sounds crazy, but I use this method a lot, it helps to keep the scope clean.
 

It's not crazy, I do it a lot, but he *does nothing with it* after that,
and the scope of the variable is limited to the function.

Thanks
Ash
www.ashleysheridan.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] [GD] Image errors

2009-07-14 Thread Martin Scotta
Why are you ussing GD?
All you need is output the image to the browser?

try this... I didn't test/run this code, but it may work...

public function showPicture( $id ) {
  header('Content-type:' . mime_content_type( $this-updir . $id .
'.png' ) );
  readfile( $this-updir . $id . '.png' );
  }

hey, look, just 2 lines!

On Tue, Jul 14, 2009 at 2:20 PM, Ashley
Sheridana...@ashleysheridan.co.uk wrote:
 On Tue, 2009-07-14 at 14:16 -0300, Martin Scotta wrote:
 On Tue, Jul 14, 2009 at 1:48 PM, Ashley
 Sheridana...@ashleysheridan.co.uk wrote:
  On Tue, 2009-07-14 at 13:41 -0300, Martin Scotta wrote:
  He is calling the function by variable
 
  something like this
 
  $func = 'var_dump';
 
  $func( new Foo );
 
  On Tue, Jul 14, 2009 at 1:30 PM, Ashley
  Sheridana...@ashleysheridan.co.uk wrote:
   On Tue, 2009-07-14 at 13:27 -0300, Martin Scotta wrote:
   $immagine = $tipo($this-updir.$id.'.png');
  
   $tipo is undefined
  
  
   On Tue, Jul 14, 2009 at 12:48 PM, Il pinguino
   volantetuxs...@codeinside.it wrote:
Hi to all
   
I get a problem processing an image with GD libraries.
   
This is my function
   
  public function showPicture($id) {
      header('Content-type: image/jpeg');
      $mime = mime_content_type($this-updir.$id.'.png');
      $type = explode('/',$mime);
      $type = 'imagecreatefrom'.$type[1];
      $immagine = $tipo($this-updir.$id.'.png');
      imagejpeg($immagine,null,100);
      imagedestroy($immagine);
  }
   
If i commentize the header function i get a lot of strange simbols 
(such
as the code of a jpeg image!) but no errors.
The result of this code is a blank page. In Firefox the title sets to
picture.php (JPEG image) and if i right-click it and click on
Proprieties i get 0px × 0px (resized as 315px × 19px).
   
P.S.: I get the same result when I write $immagine =
imagecreatefromjpeg(...)
   
(Sorry for my english)
   
Thanks in advance,
Alfio.
   
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
   
   
  
  
  
   --
   Martin Scotta
  
   Also, it doesn't look like you're actually doing anything with $type
  
   Thanks
   Ash
   www.ashleysheridan.co.uk
  
  
 
 
 
  --
  Martin Scotta
 
 
  Bottom post ;)
 
  $type = explode('/',$mime);
  $type = 'imagecreatefrom'.$type[1];
 
  $immagine = $tipo($this-updir.$id.'.png');
  imagejpeg($immagine,null,100);
  imagedestroy($immagine);
 
  I'm not sure you understood what I meant. line 2 above $type is assigned
  to the string 'imagecreatefrom'.$type[1];
 
  Now I assume that was to be used later in some sort of eval() statement,
  but its never called again, so the line really does nothing.
 
  Thanks
  Ash
  www.ashleysheridan.co.uk
 
 

 Mmmm, No

 $type = explode('/',$mime); # type is array
 $type = 'imagecreatefrom'.$type[1]; # type is a string

 He is actually re-assigning the var ussing the content of the var.
 Sounds crazy, but I use this method a lot, it helps to keep the scope clean.


 It's not crazy, I do it a lot, but he *does nothing with it* after that,
 and the scope of the variable is limited to the function.

 Thanks
 Ash
 www.ashleysheridan.co.uk





-- 
Martin Scotta

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php