Re: [PHP] tmpfile() errors?

2002-05-23 Thread Miguel Cruz

On Wed, 22 May 2002, Jas wrote:
>   $tmp_image = tmpfile();
>   $output = fopen($tmp_image, "wb");

tmpfile() opens the file, so you don't need the fopen call.

Just do $output = $tmpfile();

miguel


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




Re: [PHP] tmpfile() errors?

2002-05-22 Thread Jas

Ok I am going to put the entire class here for review... I am not the
original author, simply trying to get it to work because I think its pretty
neat:  Here is the file, asciiartist.php:
If you scroll down the page I have commented where the error occurs using
* ERRORS *

* @version 1.1 2001-12-31 18:41 CET
* @link http://www.sebastian-r.de/asciiart/index.php
* @access   public
*/

class ASCIIArtist
{
/**
* The replace characters from dark to light used by render modes 0,1
* (current version can handle 9 variations)
*
* @var  array
* @access   public
*/
var $replace_characters = array (
1 => "W",
2 => "@",
3 => "#",
4 => "*",
5 => "+",
6 => ":",
7 => ".",
8 => "’",
9 => " "
);

/**
* Possible image types
*
* @var  array
* @access   public
*/
var $image_types = array (
1 => "GIF",
2 => "JPEG",
3 => "PNG"
);

/**
* Image file handler
*
* @var  string
* @access   public
*/
var $image = NULL;

/**
* Image file height
*
* @var  integer
* @access   public
*/
var $image_height = 0;

/**
* Image file height
*
* @var  integer
* @access   public
*/
var $image_width = 0;

/**
* Container for the rendered HTML/ASCII image
*
* @var  string
* @access   public
*/
var $image_html = NULL;

/**
* CSS for the HTML Image Output
*
* @var  string
* @access   public
*/
var $image_css = "
color   : #00;
background-color: #FF;
font-size   : 8px;
font-family : \"Courier New\", Courier, mono;
line-height : 5px;
letter-spacing  : -1px;
";

/**
* Formatting the HTML Image using CSS
*
* Tip: Use width-fixed fonts such as Courier only.
*
* @paramstring$cssCSS Content
* @access   public
* @see  $image_css
*/
function setImageCSS ($css)
{
$this->image_css = $css;
}

/**
* Returns the hex string of a rgb array
*
* Example:
* $rbg = array("red" -> 255, "green" -> 255, "blue" -> 255);
* rgb2hex($rgb) will return "FF"
*
* @paramarray   $rgbAn array of red, green and blue values
* @return   string  The hex values as one string
* @access   private
*/
function _rgb2hex($rgb)
{
return
sprintf("%02X%02X%02X",$rgb["red"],$rgb["green"],$rgb["blue"]);
} // end func rgb2hex

/**
* Renders the image into HTML
*
* The following modes are implemented:
* 1 = black/white using $replaceCharacters by brightness,
* 2 = colourized using $replaceCharacters by brightness,
* 3 = colourized using a fixed character definded by $fixedChar.
* A resolution of 1 means that every pixel is being replaced,
* whereas 5 for example means a scanned block of 5 pixel height and
width,
* resulting in less data to replace.
*
* @paraminteger $mode   Current version can handle mode 1, 2 or
3
* @paraminteger $resolution Resolution for scanning the bitmap.
* @paramstring  $fixed_char Needed for mode 3
* @paramboolean $flip_h Flip output horizontally?
* @paramboolean $flip_v Flip output vertically?
* @access   public
* @see  getHTMLImage(), $replace_characters
*/
function renderHTMLImage($mode = 1, $resolution = 2, $fixed_char = "@",
$flip_h = false, $flip_v = false)
{
// Minimum value for $resolution is 1
if ($resolution < 1) {
$resolution = 1;
}

// Different loops for flipping
// (btw.: Can someone give me a hint how to implement
// dynamic operators or the like to get rid of those endless cases?)
if (!$flip_h && !$flip_v) {
// Y-Axis
for ($y = 0; $y < $this->image_height; $y += $resolution)
{
// X-Axis
for ($x = 0; $x < $this->image_width; $x += $resolution)
{
$this->renderPixel($mode, $x, $y, $fixed_char);
}
$this->image_html .= "\n";
}
}
else if ($flip_h && !$flip_v) {
// Y-Axis
for ($y = 0; $y < $this->image_height; $y += $resolution)
{
// X-Axis
for ($x = $this->image_width; $x > 0; $x -= $resolution)
{
$this->renderPixel($mode, $x, $y, $fixed_char);
}
$this->image_html .= "\n";
}
}
else if (!$flip_h && $flip_v) {
// Y-Axis
for ($y = $this->image_height; $y > 0; $y -= $resolution)
{
// X-Axis
for ($x = 0; $x < $this->image_width; $x += $resolut

Re: [PHP] tmpfile() errors?

2002-05-22 Thread 1LT John W. Holmes

You're not even trying to open a file. You're trying to open a Resource,
which makes me think that fopen() is being called twice or something. You
obviously have something very wrong.

Can you show the code around these lines where you're trying to open the
file? All of the errors are because of the first one.

---John Holmes...

> -Original Message-
> From: Jas [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 22, 2002 4:18 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] tmpfile() errors?
>
>
> Here are the errors I am recieving:
> Warning: fopen("Resource id #4","wb") - Permission denied in
> /path/to/asciiartist.php on line 295
>
> Warning: Supplied argument is not a valid File-Handle resource in
> /path/to/asciiartist.php on line 296
>
> Warning: Supplied argument is not a valid File-Handle resource in
> /path/to/asciiartist.php on line 297
>
> Warning: getimagesize: Unable to open 'Resource id #4' for reading. in
> /path/to/asciiartist.php on line 303
> ASCIIArtist(): Cannot determine image type of shared/image02.jpg.
>
> I have checked the file permissions for the files and directory in
question
> and they are all set to read & write, so I know this is not the problem.
> Here is the function that I am trying to get to work.
>
> function ASCIIArtist($image)
> {
> if ($input = @fopen($image, "rb")) {
>   $image_data = fread ($input, 2048576);
>   fclose($input);
>   $tmp_image = tmpfile();
>   $output = fopen($tmp_image, "wb");
>   fwrite($output, $image_data);
>   fclose($output);
> } else {
> exit("Cannot access ".$image." for reading. (Does not exist or
> has wrong permissions)");
> }
>
> This code is from http://www.sebastian-r.de/.  And everything works fine
> until it hits this function. Could I get some enlightenment on why it
cannot
> create a temp file named $tmp_image?  (ecspecially when the permissions
for
> the file are correct?)  Thanks in advance,
> Jas
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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




RE: [PHP] tmpfile() errors?

2002-05-22 Thread James E. Hicks III

I'd check the owner of the directory you are trying to write to. It needs to be
owned by the same user as the httpd process runs as.

James

-Original Message-
From: Jas [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 22, 2002 4:18 PM
To: [EMAIL PROTECTED]
Subject: [PHP] tmpfile() errors?


Here are the errors I am recieving:
Warning: fopen("Resource id #4","wb") - Permission denied in
/path/to/asciiartist.php on line 295

Warning: Supplied argument is not a valid File-Handle resource in
/path/to/asciiartist.php on line 296

Warning: Supplied argument is not a valid File-Handle resource in
/path/to/asciiartist.php on line 297

Warning: getimagesize: Unable to open 'Resource id #4' for reading. in
/path/to/asciiartist.php on line 303
ASCIIArtist(): Cannot determine image type of shared/image02.jpg.

I have checked the file permissions for the files and directory in question
and they are all set to read & write, so I know this is not the problem.
Here is the function that I am trying to get to work.

function ASCIIArtist($image)
{
if ($input = @fopen($image, "rb")) {
  $image_data = fread ($input, 2048576);
  fclose($input);
  $tmp_image = tmpfile();
  $output = fopen($tmp_image, "wb");
  fwrite($output, $image_data);
  fclose($output);
} else {
exit("Cannot access ".$image." for reading. (Does not exist or
has wrong permissions)");
}

This code is from http://www.sebastian-r.de/.  And everything works fine
until it hits this function. Could I get some enlightenment on why it cannot
create a temp file named $tmp_image?  (ecspecially when the permissions for
the file are correct?)  Thanks in advance,
Jas



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


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