Ejemplo n.º 1
0
 $ext = strtolower(array_pop($parts));
 //echo $ext."($upload_image_file)\n";
 switch (strtolower($ext)) {
     case 'jpeg':
     case 'jpg':
         $upload_image = imagecreatefromjpeg($tmp_image_file);
         break;
     case 'gif':
         $upload_image = imagecreatefromgif($tmp_image_file);
         break;
     case 'png':
         $upload_image = imagecreatefrompng($tmp_image_file);
         break;
 }
 $imagebg = imageCreateFromstring(GRID_BLOCK);
 imageSetTile($whole_image, $imagebg);
 imageFilledRectangle($whole_image, 0, 0, $size['x'], $size['y'], IMG_COLOR_TILED);
 imagecopy($whole_image, $upload_image, 0, 0, 0, 0, $img_size[0], $img_size[1]);
 //imagepng($whole_image);
 for ($i = 0; $i < $size['y']; $i += BLK_HEIGHT) {
     for ($j = 0; $j < $size['x']; $j += BLK_WIDTH) {
         $map_x = $j + $low_x;
         $map_y = $i + $low_y;
         $r_x = $map_x;
         $r_y = $map_y;
         $GRD_WIDTH = BLK_WIDTH * G_WIDTH;
         $cb = $map_x / BLK_WIDTH + $map_y / BLK_HEIGHT * ($GRD_WIDTH / BLK_WIDTH);
         // bool imagecopy ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h )
         imagecopy($dest, $whole_image, 0, 0, $j, $i, BLK_WIDTH, BLK_HEIGHT);
         ob_start();
         imagepng($dest);
Ejemplo n.º 2
0
function check_selection_main()
{
    //global $b_row;
    # check the status of the block.
    ###################################################
    if (USE_LOCK_TABLES == 'Y') {
        $sql = "LOCK TABLES blocks WRITE, temp_orders WRITE, currencies READ, prices READ, banners READ";
        $result = mysql_query($sql) or die(" <b>Dear Webmaster: The current MySQL user does not have permission to lock tables. Please give this user permission to lock tables, or turn off locking in the Admin. To turn off locking in the Admin, please go to Main Config and look under the MySQL Settings.<b>");
    } else {
        // poor man's lock
        $sql = "UPDATE `config` SET `val`='YES' WHERE `key`='SELECT_RUNNING' AND `val`='NO' ";
        $result = mysql_query($sql) or die(mysql_error());
        if (mysql_affected_rows() == 0) {
            // make sure it cannot be locked for more than 30 secs
            // This is in case the proccess fails inside the lock
            // and does not release it.
            $unix_time = time();
            // get the time of last run
            $sql = "SELECT * FROM `config` where `key` = 'LAST_SELECT_RUN' ";
            $result = @mysql_query($sql);
            $t_row = @mysql_fetch_array($result);
            if ($unix_time > $t_row['val'] + 30) {
                // release the lock
                $sql = "UPDATE `config` SET `val`='NO' WHERE `key`='SELECT_RUNNING' ";
                $result = @mysql_query($sql) or die(mysql_error());
                // update timestamp
                $sql = "REPLACE INTO config (`key`, `val`) VALUES ('LAST_SELECT_RUN', '{$unix_time}')  ";
                $result = @mysql_query($sql) or die(mysql_error());
            }
            usleep(5000000);
            // this function is executing in another process. sleep for half a second
            check_selection_main();
            return;
        }
    }
    ####################################################
    $upload_image_file = get_tmp_img_name();
    $size = getimagesize($upload_image_file);
    $new_size = get_required_size($size[0], $size[1]);
    $block_id = $_REQUEST['block_id'];
    //print_r($_REQUEST);
    // get width and height of uploaded image
    //echo "[".$size[0]." ".$size[1]."] ";
    //echo $block_id;
    if (function_exists("imagecreatetruecolor")) {
        $dest = imagecreatetruecolor(BLK_WIDTH, BLK_HEIGHT);
        $whole_image = imagecreatetruecolor($new_size[0], $new_size[1]);
    } else {
        $dest = imagecreate(BLK_WIDTH, BLK_HEIGHT);
        $whole_image = imagecreate($new_size[0], $new_size[1]);
    }
    $parts = split('\\.', $upload_image_file);
    $ext = strtolower(array_pop($parts));
    //echo $ext."($upload_image_file)\n";
    switch ($ext) {
        case 'jpeg':
        case 'jpg':
            $upload_image = imagecreatefromjpeg($upload_image_file);
            break;
        case 'gif':
            $upload_image = imagecreatefromgif($upload_image_file);
            break;
        case 'png':
            $upload_image = imagecreatefrompng($upload_image_file);
            break;
    }
    // create the requ
    //$imagebg = imageCreateFromPNG (SERVER_PATH_TO_ADMIN.'temp/block.png'); // transparent PNG
    //echo GRID_BLOCK;
    $imagebg = imageCreateFromstring(GRID_BLOCK);
    imageSetTile($whole_image, $imagebg);
    imageFilledRectangle($whole_image, 0, 0, $new_size[0], $new_size[1], IMG_COLOR_TILED);
    imagecopy($whole_image, $upload_image, 0, 0, 0, 0, $size[0], $size[1]);
    //imagepng($whole_image);
    for ($i = 0; $i < $size[1]; $i += BLK_HEIGHT) {
        for ($j = 0; $j < $size[0]; $j += BLK_WIDTH) {
            $map_x = $j + $_REQUEST['map_x'];
            $map_y = $i + $_REQUEST['map_y'];
            $r_x = $map_x;
            $r_y = $map_y;
            //echo "map_x: $map_x map_y: $map_y \n";
            $GRD_WIDTH = BLK_WIDTH * G_WIDTH;
            $cb = $map_x / BLK_WIDTH + $map_y / BLK_HEIGHT * ($GRD_WIDTH / BLK_WIDTH);
            $in_str = $in_str . "{$comma}{$cb}";
            $comma = ',';
            $block_info[$cb]['map_x'] = $map_x;
            $block_info[$cb]['map_y'] = $map_y;
            // bool imagecopy ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h )
            imagecopy($dest, $whole_image, 0, 0, $j, $i, BLK_WIDTH, BLK_HEIGHT);
            //echo "imagecopy ( $dest, $whole_image, 0, 0, $j, $i, ".BLK_HEIGHT.", '".BLK_WIDTH."' );";
            ob_start();
            imagepng($dest);
            $data = ob_get_contents();
            ob_end_clean();
            $data = base64_encode($data);
            $block_info[$cb]['image_data'] = $data;
        }
    }
    //
    imagedestroy($dest);
    imagedestroy($upload_image);
    //print_r ($block_info);
    // create a temporary order and place the blocks on a temp order
    place_temp_order($in_str, $price);
    //echo "in_str is:".$in_str;
    reserve_temp_order_pixels($block_info, $in_str);
    ###################################################
    if (USE_LOCK_TABLES == 'Y') {
        $sql = "UNLOCK TABLES";
        $result = mysql_query($sql) or die(mysql_error() . " <b>Dear Webmaster: The current MySQL user set in config.php does not have permission to lock tables. Please give this user permission to lock tables, or set USE_LOCK_TABLES to N in the config.php file that comes with this script.<b>");
    } else {
        // release the poor man's lock
        $sql = "UPDATE `config` SET `val`='NO' WHERE `key`='SELECT_RUNNING' ";
        mysql_query($sql);
        $unix_time = time();
        // update timestamp
        $sql = "REPLACE INTO config (`key`, `val`) VALUES ('LAST_SELECT_RUN', '{$unix_time}')  ";
        $result = @mysql_query($sql) or die(mysql_error());
    }
    ####################################################
}
Ejemplo n.º 3
0
<?php

## Увеличение картинки со сглаживанием.
$tile = imageCreateFromJpeg("sample1.jpg");
$im = imageCreateTrueColor(800, 600);
imageFill($im, 0, 0, imageColorAllocate($im, 0, 255, 0));
imageSetTile($im, $tile);
// Создаем массив точек со случайными координатами.
$p = [];
for ($i = 0; $i < 4; $i++) {
    array_push($p, mt_rand(0, imageSX($im)), mt_rand(0, imageSY($im)));
}
// Рисуем закрашенный многоугольник.
imageFilledPolygon($im, $p, count($p) / 2, IMG_COLOR_TILED);
// Выводим результат.
header("Content-type: image/jpeg");
// Выводим картинку с максимальным качеством (100).
imageJpeg($im, '', 100);
// Можно было сжать с помощью PNG.
#header("Content-type: image/png");
#imagePng($im);
$filename = get_tmp_img_name();
if (file_exists($filename)) {
    $handle = fopen($filename, 'r');
    $contents = fread($handle, filesize($filename));
    $size = getimagesize($filename);
    fclose($handle);
    $image = imagecreatefromstring($contents);
} else {
    $image = imagecreatefrompng('pointer.png');
    $size = getimagesize('pointer.png');
}
$new_size = get_required_size($size[0], $size[1]);
$out = imagecreatetruecolor($new_size[0], $new_size[1]);
$imagebg = imageCreateFromPNG('block.png');
// tile filler
imageSetTile($out, $imagebg);
imageFilledRectangle($out, 0, 0, $new_size[0], $new_size[1], IMG_COLOR_TILED);
imagecopy($out, $image, 0, 0, 0, 0, $size[0], $size[1]);
if (MDS_RESIZE == 'YES') {
    // make it smaller
    $newsize_img = imagecreate($new_size[0], $new_size[1]);
    imagecopyresampled($newsize_img, $image, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
    imagecopy($out, $newsize_img, 0, 0, 0, 0, $new_size[0], $new_size[1]);
}
//);
//imagestring ($out, 2, 10, 10, 'hello'.$new_size[0]." - ".$new_size[1], 0 );
//imagedestroy($image);
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
Ejemplo n.º 5
0
 function generate_jpg($file_path, $size, $stars, $value, $output = '')
 {
     $image_set = imagecreatefromjpeg($file_path);
     $star_empty = imagecreate($size, $size);
     $star_filled = imagecreate($size, $size);
     $image = imagecreate($stars * $size, $size);
     imagecopy($star_empty, $image_set, 0, 0, 0, 0, $size, $size);
     imagecopy($star_filled, $image_set, 0, 0, 0, $size * 2, $size, $size);
     imageSetTile($image, $star_empty);
     imagefilledrectangle($image, 0, 0, $stars * $size, $size, IMG_COLOR_TILED);
     imageSetTile($image, $star_filled);
     imagefilledrectangle($image, 0, 0, $value * $size, $size, IMG_COLOR_TILED);
     if ($output == '') {
         Header("Content-type: image/jpg");
         imagejpeg($image);
     } else {
         imagejpeg($image, $output);
     }
     imagedestroy($image);
     imagedestroy($image_set);
     imagedestroy($star_empty);
     imagedestroy($star_filled);
 }