/**
  * Create an image from the given image handler, cache it and return the file content.
  *
  * Always try to retrive the image from the cache before you compute it.
  * 
  * Warning: this function uses the output buffer. If you expect collisions 
  * modify the code.
  *
  * @param    string  Image-ID. Used as a part of the cache filename.
  *                   Use md5() to generate a "unique" ID for your image
  *                   based on characteristic values such as the color, size etc.
  * @param    string  Image handler to create the image from.
  * @param    string  Image type: gif, jpg, png, wbmp. Also used as filename suffix.
  *                   If an unsupported type is requested the functions tries to 
  *                   fallback to a supported type before throwing an exeption.
  * @return   string  Image content returned by ImageGIF/... 
  * @throws   Cache_Error
  * @access   public
  * @see      getImage()
  */
 function cacheImage($id, $img, $format = 'png')
 {
     if (!$id) {
         return new Cache_Error('You must provide an ID for and image to be cached!', __FILE__, __LINE__);
     }
     $id = $this->generateID($id, $format);
     $types = ImageTypes();
     // Check if the requested image type is supported by the GD lib.
     // If not, try a callback to the first available image type.
     if (!isset($this->imagetypes[$format]) || !($types & $this->imagetypes[$format])) {
         foreach ($this->imagetypes as $supported => $bitmask) {
             if ($types & $bitmask) {
                 new Cache_Error("The build in GD lib does not support the image type {$format}. Fallback to {$supported}.", __FILE__, __LINE__);
             } else {
                 return new Cache_Error("Hmm, is your PHP build with GD support? Can't find any supported types.", __FILE__, __LINE__);
             }
         }
     }
     if ($image = $this->get($id, $this->cache_group)) {
         return $image;
     }
     // save the image to the output buffer, write it to disk and
     // return the image.
     ob_end_clean();
     ob_start();
     if (strtoupper($format) == 'JPG') {
         $genFormat = 'JPEG';
     } else {
         $genFormat = strtoupper($format);
     }
     // generate the image
     $func = 'Image' . $genFormat;
     $func($img);
     ImageDestroy($img);
     ob_end();
     $image = ob_get_contents();
     ob_end_clean();
     // save the generated image to disk
     $this->save($id, $image, 0, $this->cache_group);
     return $image;
 }
Ejemplo n.º 2
0
<?php

ob_start();
ini_set('display_errors', 0);
$main_dir = dirname(__FILE__);
if (isset($_REQUEST['type']) && isset($_REQUEST['diameter'])) {
    $curDate = date('Ymd');
    $fileName = $main_dir . '/logs/' . $curDate . '.txt';
    if (file_exists($fileName)) {
        $content = file_get_contents($fileName);
        $content .= "\n" . ucfirst($_REQUEST['type']) . ' Diameter' . $_REQUEST['diameter'];
        file_put_contents($fileName, $content);
        echo json_encode(array('message' => 'Success'));
        die;
    } else {
        $content .= ucfirst($_REQUEST['type']) . ' Diameter' . $_REQUEST['diameter'];
        file_put_contents($fileName, $content);
        echo json_encode(array('message' => 'Success'));
        die;
    }
} else {
    echo json_encode(array('message' => 'Parameter Missing.'));
    die;
}
ob_end();
                        ),
                    ),
                ),
            )));

            $this->inputFilter = $inputFilter;
        }

        return $this->inputFilter;
    }
<?php 
        echo "}\n";
        ?>

<?php 
        ob_end($fileName);
    }
} else {
    echo "No columns in table {$argv['2']}\n";
}
function createDir($path)
{
    if (!file_exists($path)) {
        mkdir($path, 0755);
        echo "Dir created {$path}\n";
    } else {
        echo "Dir exists {$path}\n";
    }
}
function ob_end($fileName)
{
Ejemplo n.º 4
0
function abtest_ob_end()
{
    if (get_option('abtest_do_shortcode_on_output_buffer')) {
        ob_end();
    }
}