function saveWatermark($src, $path, $watermark)
{
    $imgsrc = loadImage($src);
    $width = imagesx($imgsrc);
    $height = imagesy($imgsrc);
    $imgWZ = loadImage($watermark);
    $widthWZ = imagesx($imgWZ);
    $heightWZ = imagesy($imgWZ);
    //bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
    imagecopyresampled($imgsrc, $imgWZ, $width - $widthWZ / 4, $height - $heightWZ / 4, 0, 0, $widthWZ / 4, $heightWZ / 4, $widthWZ, $heightWZ);
    imagejpeg($imgsrc, $path . basename($src));
}
示例#2
0
文件: test3.php 项目: yehchge/resize
<?php

/**
 *  @desc 呼叫 test5.php 檔案,將圖片裁切後顯示,不產生檔案
 */
// makes the process simpler
function loadImage($url, $width, $height)
{
    echo 'test5.php?url=', urlencode($url), '&w=', $width, '&h=', $height;
}
?>

<img src="<?php 
loadImage('image.jpg', 300, 300);
?>
" />
示例#3
0
if ($delete) {
    $f = new FtpUtil();
    $f->staticServerDelete($AVATAR_REMOTE_FILE);
    $user->hasAvatar = 0;
    $user->save();
    FlashMessage::add('Imaginea a fost ștearsă.', 'info');
    util_redirect('preferinte');
}
$rawFileList = glob($AVATAR_RAW_GLOB);
if (empty($rawFileList)) {
    FlashMessage::add('Imaginea dumneavoastră de profil nu mai există. Vă rugăm să o reîncărcați.');
    util_redirect(util_getWwwRoot());
}
$rawFileName = $rawFileList[0];
$canvas = imagecreatetruecolor(AVATAR_RESOLUTION, AVATAR_RESOLUTION);
$image = loadImage($rawFileName);
imagecopyresampled($canvas, $image, 0, 0, $x0, $y0, AVATAR_RESOLUTION, AVATAR_RESOLUTION, $side, $side);
sharpenImage($canvas);
$tmpFileName = tempnam(Config::get('global.tempDir'), 'dex_avatar_');
imagejpeg($canvas, $tmpFileName, AVATAR_QUALITY);
$f = new FtpUtil();
$f->staticServerPut($tmpFileName, $AVATAR_REMOTE_FILE);
unlink($rawFileName);
unlink($tmpFileName);
$user->hasAvatar = 1;
$user->save();
FlashMessage::add('Imaginea a fost salvată.', 'info');
util_redirect('preferinte');
/****************************************************************************/
/* Load an image by its (supported) type */
function loadImage($file)
示例#4
0
                 foreach ($fieldNames as $value) {
                     $notices[] = $_lang["eb_notice_{$value}"];
                 }
                 $pl['notice'] = str_replace("[+notices+]", implode(", ", $notices), $_lang['eb_notice']);
             }
             $output .= $modx->parseText($template, $pl, '[+', '+]');
         } else {
             die($_lang['eb_accessdenied']);
         }
     }
     break;
 case "add":
     $LoginUserID = $modx->getLoginUserID();
     if ($LoginUserID !== NULL) {
         if ($_POST['act'] == "add") {
             $fields = array('pagetitle' => $modx->db->escape($_POST[pagetitle]), 'content' => $modx->db->escape($_POST[content]), 'contact' => $modx->db->escape($_POST[contact]), 'price' => (int) $_POST[price], 'parent' => (int) $_POST[parent], 'city' => (int) $_POST[city], 'published' => 1, 'image' => loadImage($imageDir, $imagesize), 'createdby' => $LoginUserID, 'createdon' => time(), 'context' => $context);
             $checkRequired = checkRequiredArray($required, $fields);
             if ($checkRequired[0] === false) {
                 // Если обязательные поля не заполнены
                 $fields[published] = 0;
                 $modx->db->insert($fields, $mod_table);
                 header("Location: http://" . $_SERVER['SERVER_NAME'] . $modx->makeUrl($idediturl, "", "eb=" . $modx->db->getInsertId()) . "&notice={$checkRequired['1']}");
                 die;
             } else {
                 $modx->db->insert($fields, $mod_table);
             }
             header("Location: http://" . $_SERVER['SERVER_NAME'] . $modx->makeUrl($idafterediturl));
             die("");
         } else {
             if ($tpladd == "") {
                 $template = file_get_contents($snippetPath . "tpl/add.tpl");
<?php

/**
 * Flaming Shame Raster to SVG converter
 *
 * @author  Eric Meyers, Amelia Bellamy-Royds, Robin Cafolla
 * @arg     string url      Takes a single string url or path to local image to
 *                          convert from raster to SVG.
 */
if (count($argv) < 1) {
    throw new \RuntimeException('Too few arguments passed to converter');
}
$url = $argv[1];
$img = loadImage($url);
if (!!$img) {
    header('Content-type: image/svg+xml');
    echo generateSVG($img);
} else {
    echo "<a href=\"{$url}\">Bad image file</a>";
}
/**
 * Generates svg from raster
 *
 * @param GDImageIdentifier $img    Raster image to convert to svg
 * @return string                   SVG xml
 */
function generateSVG($img)
{
    $w = imagesx($img);
    // image width
    $h = imagesy($img);
示例#6
0
function loadItemImages($bigImgUrl, $smallImgUrl, $destName)
{
    if (file_exists(getNormImagePath($destName))) {
        print "Image already exists - {$destName}\n";
        return;
    }
    // Загрузка большого изображения
    $fName = loadImage($bigImgUrl, getNormImagePath($destName, false));
    if (PEAR::isError($fName)) {
        print "Can't load image: " . $fName->getMessage() . "\n";
        $fName = loadImage($smallImgUrl, getSmallImagePath($destName, false));
        if (PEAR::isError($fName)) {
            print "Can't load thumb image: " . $fName->getMessage() . "\n";
            return;
        }
        // Конвертирование в используемый нами формат
        $newName = replaceExt($fName, IMAGE_EXT);
        $img = Image_Transform::factory("GD");
        if (PEAR::isError($img)) {
            print $img->getMessage();
            return;
        }
        // Создание уменьшенного изображения
        $img->load($newName);
        // Если изображение больше стандартных размеров - обработать
        if ($img->getImageWidth() > MAX_WIDTH_THUMBIMAGE || $img->getImageHeight() > MAX_HEIGHT_THUMBIMAGE) {
            $img->scaleByX(MAX_WIDTH_THUMBIMAGE);
            $img->scaleByY(MAX_HEIGHT_THUMBIMAGE);
        }
        $img->save(getSmallImagePath($destName), IMAGE_EXT, 100);
        $img->free();
        // Удаление временного загруженного файла
        if (strcmp($fName, $newName) != 0) {
            unlink($fName);
        }
        return;
    }
    // Конвертирование в используемый нами формат
    $newName = replaceExt($fName, IMAGE_EXT);
    $img = Image_Transform::factory("GD");
    if (PEAR::isError($img)) {
        print $img->getMessage();
        return;
    }
    $img->load($fName);
    // Если изображение больше стандартных размеров - обработать
    if ($img->getImageWidth() > MAX_WIDTH_NORMIMAGE || $img->getImageHeight() > MAX_HEIGHT_NORMIMAGE) {
        $img->scaleByX(MAX_WIDTH_NORMIMAGE);
        $img->scaleByY(MAX_HEIGHT_NORMIMAGE);
    }
    $img->save($newName, IMAGE_EXT, 100);
    $img->free();
    // Удаление временного загруженного файла
    if (strcmp($fName, $newName) != 0) {
        unlink($fName);
    }
    // Создание уменьшенного изображения
    $img->load($newName);
    if ($img->getImageWidth() > MAX_WIDTH_THUMBIMAGE || $img->getImageHeight() > MAX_HEIGHT_THUMBIMAGE) {
        $img->scaleByX(MAX_WIDTH_THUMBIMAGE);
        $img->scaleByY(MAX_HEIGHT_THUMBIMAGE);
    }
    $img->save(getSmallImagePath($destName), IMAGE_EXT, 100);
    $img->free();
}
if (is_file($crontabFile)) {
    include $crontabFile;
}
if (WEB_CRONTAB && is_writable($crontabFile) && ((!isset($crontab) || $crontab['date_last_success'] != getDateFromTimestamp(time())) && (!is_file($crontabFile) || isset($crontab) && $crontab['time_last_try'] < time() - TIME_TO_WAIT_FOR_PARALLEL_ARCHIVE))) {
    $crontab['time_last_try'] = time();
    $crontab['date_last_success'] = '2000-12-31';
    saveConfigFile($crontabFile, $crontab, "crontab");
    printDebug('==========================<br>
				CRONTAB BEGIN/			  <br>
				==========================<br>
				');
    require_once INCLUDE_PATH . '/core/include/PmvConfig.class.php';
    require_once INCLUDE_PATH . '/core/include/ApplicationController.php';
    $r =& Request::getInstance();
    $r->setModuleName('send_mail');
    $r->setCrontabAllowed();
    ApplicationController::init();
    printDebug('==========================<br>
				CRONTAB END/			  <br>
				==========================<br>
				');
    $crontab['date_last_success'] = getDateFromTimestamp(time());
    saveConfigFile($crontabFile, $crontab, "crontab");
}
$db->close();
redirectToUrlIfNecessary();
loadImage($logo, $idSite);
// flush content for display
if (DEBUG) {
    ob_end_flush();
}
示例#8
0
文件: image.php 项目: soundake/pd
function createThumbnail($source, $destination, $newwidth, $newheight, $action = 'strict', $type = 2)
{
    $img = $out = loadImage($source, $type);
    $ims = getimagesize($source);
    $width = $ims[0];
    $height = $ims[1];
    $width_rate = $newwidth / $width;
    $height_rate = $newheight / $height;
    switch ($action) {
        case 'max':
            if ($width_rate > $height_rate) {
                $newwidth_prop = $width * $height_rate;
                $newheight_prop = $newheight;
            } else {
                $newwidth_prop = $newwidth;
                $newheight_prop = $height * $width_rate;
            }
            if ($newwidth_prop > $width || $newheight_prop > $height) {
                return false;
            }
            $out = imagecreatetruecolor($newwidth_prop, $newheight_prop);
            imagecopyresampled($out, $img, 0, 0, 0, 0, $newwidth_prop, $newheight_prop, $width, $height);
            break;
        case 'maxsize':
            if ($width_rate > $height_rate) {
                $newwidth_prop = $width * $height_rate;
                $newheight_prop = $newheight;
            } else {
                $newwidth_prop = $newwidth;
                $newheight_prop = $height * $width_rate;
            }
            $newwidth_prop = $newwidth_prop > $width ? $width : $newwidth_prop;
            $newheight_prop = $newheight_prop > $height ? $height : $newheight_prop;
            $dst_x = $newwidth / 2 - $newwidth_prop / 2;
            $dst_y = $newheight / 2 - $newheight_prop / 2;
            $out = imagecreatetruecolor($newwidth, $newheight);
            $background = imagecolorallocate($out, 255, 255, 255);
            imagefilledrectangle($out, 0, 0, $newwidth, $newheight, $background);
            imagecopyresampled($out, $img, $dst_x, $dst_y, 0, 0, $newwidth_prop, $newheight_prop, $width, $height);
            break;
        case 'crop':
            if ($newwidth > $width && $newheight > $height) {
                return false;
            }
            if ($width_rate > $height_rate) {
                $newwidth_prop_crop = $newwidth;
                $newheight_prop_crop = $height * $width_rate;
                $src_x = 0;
                $src_y = ($height - $newheight / $newheight_prop_crop * $height) / 2;
            } else {
                $newwidth_prop_crop = $width * $height_rate;
                $newheight_prop_crop = $newheight;
                $src_x = ($width - $newwidth / $newwidth_prop_crop * $width) / 2;
                $src_y = 0;
            }
            $out = imagecreatetruecolor($newwidth, $newheight);
            imagecopyresampled($out, $img, 0, 0, $src_x, $src_y, $newwidth_prop_crop, $newheight_prop_crop, $width, $height);
            break;
        case 'exact':
        case 'strict':
            if ($newwidth > $width || $newheight > $height) {
                return false;
            }
            $out = imagecreatetruecolor($newwidth, $newheight);
            imagecopyresampled($out, $img, 0, 0, 0, 0, $newheight, $newwidth, $width, $height);
            break;
    }
    saveImage($out, $destination, $type);
    imagedestroy($img);
    return true;
}
示例#9
0
function loadItemImages($bigImgUrl, $smallImgUrl, $destName)
{
    $oldFile = realpath(getNormImagePath($destName));
    if (file_exists($oldFile)) {
        unlink($oldFile);
    }
    // Загрузка большой картинки
    $fName = loadImage($bigImgUrl, "data/tmp/{$destName}");
    if (PEAR::isError($fName)) {
        print $fName->getMessage() . "\n";
        return $fName;
    }
    // Обработка большой картинки
    $newName = replaceExt(getNormImagePath($destName), IMAGE_EXT);
    resizeImage($fName, $newName, MAX_WIDTH_NORMIMAGE, MAX_HEIGHT_NORMIMAGE);
    // Обработка маленкой картинки
    $newSmallName = replaceExt(getSmallImagePath($destName), IMAGE_EXT);
    resizeImage($fName, $newSmallName, MAX_WIDTH_THUMBIMAGE, MAX_HEIGHT_THUMBIMAGE);
    unlink($fName);
}
示例#10
0
 case 'save':
     $fields = array();
     $fields = array('pagetitle' => $modx->db->escape($_POST[pagetitle]), 'content' => $modx->db->escape($_POST[content]), 'contact' => $modx->db->escape($_POST[contact]), 'price' => (int) $_POST[price], 'parent' => (int) $_POST[parent], 'city' => (int) $_POST[city], 'hit' => (int) $_POST[hit], 'createdby' => (int) $_POST[createdby], 'image' => loadImage($imageDir), 'createdon' => time(), 'context' => $modx->db->escape($_POST[context]));
     $fields['published'] = isset($_POST[published]) ? 1 : 0;
     $fields['allcity'] = isset($_POST[allcity]) ? 1 : 0;
     $modx->db->insert($fields, $mod_table);
     header("Location: {$_SERVER['REQUEST_URI']}");
     break;
     //Обновление записи в БД
 //Обновление записи в БД
 case 'update':
     $fields = array('pagetitle' => $modx->db->escape($_POST[pagetitle]), 'content' => $modx->db->escape($_POST[content]), 'contact' => $modx->db->escape($_POST[contact]), 'price' => (int) $_POST[price], 'parent' => (int) $_POST[parent], 'city' => (int) $_POST[city], 'hit' => (int) $_POST[hit], 'createdby' => (int) $_POST[createdby], 'context' => $modx->db->escape($_POST[context]));
     $fields['published'] = isset($_POST[published]) ? 1 : 0;
     $fields['allcity'] = isset($_POST[allcity]) ? 1 : 0;
     if (isset($_FILES['image'])) {
         $fields['image'] = loadImage($imageDir);
     }
     $query = $modx->db->update($fields, $mod_table, "id = " . (int) $_POST['item_id'] . "");
     header("Location: {$_SERVER['REQUEST_URI']}");
     break;
     //Перезагрузка страницы (сброс $_POST)
 //Перезагрузка страницы (сброс $_POST)
 case 'reload':
     header("Location: {$_SERVER['REQUEST_URI']}");
     break;
     //Удаление записи в БД
 //Удаление записи в БД
 case 'delete':
     $modx->db->delete($mod_table, "id = " . (int) $_POST[item_id]);
     header("Location: {$_SERVER['REQUEST_URI']}");
     break;
示例#11
0
/**
 * Resize and merger images to one image by min width
 * @param $files array with file paths
 * @return new file data array
 */
function mergeImages($files)
{
    global $TMPFILES;
    global $MIN_IMAGE_WIDTH, $TMP_PATH;
    // from config
    $res = array();
    $TMPFILES[] = $TMP_PATH . '/' . substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 16);
    $res['tmpFileName'] = end($TMPFILES);
    // load images
    $width = 2147483647;
    foreach ($files as $key => &$file) {
        $imgData = loadImage($file['tmpFileName']);
        if (empty($imgData)) {
            throw new Exception("Bad image.");
        }
        $file = array_merge($file, $imgData);
        $file['width'] = $file['imageInfo'][0];
        $file['height'] = $file['imageInfo'][1];
        if ($width > $file['width']) {
            $width = $file['width'];
        }
    }
    if ($width < $MIN_IMAGE_WIDTH) {
        $width = $MIN_IMAGE_WIDTH;
    }
    $height = 0;
    foreach ($files as $key => &$file) {
        $file['newWidth'] = $width;
        if ($file['width']) {
            $file['newHeight'] = $width / $file['width'] * $file['height'];
            $height += $file['newHeight'];
        }
    }
    $height += count($files) - 1;
    $dstImage = imagecreatetruecolor($width, $height);
    imagefill($dstImage, 0, 0, 0xffffff);
    $hgh = 0;
    foreach ($files as $key => &$file) {
        imagecopyresampled($dstImage, $file['image'], 0, $hgh, 0, 0, $width, $file['newHeight'], $file['width'], $file['height']);
        $hgh += $file['newHeight'] + 1;
        imagedestroy($file['image']);
        deleteFile($file['tmpFileName']);
    }
    imagepng($dstImage, $res['tmpFileName']);
    $res['contentType'] = 'image/png';
    $res['hash'] = hash_file('sha256', $res['tmpFileName']);
    $res['srcPathInfo'] = pathinfo(basename($src));
    $res['ext'] = 'png';
    $res['imgType'] = 3;
    imagedestroy($dstImage);
    return $res;
}
示例#12
0
 public function setLine($thickness = 1, $style = NULL, $brush = NULL)
 {
     if (!$this->checkImage()) {
         return false;
     }
     imagesetthickness($this->img, $thickness);
     if (is_array($style)) {
         $style_lst = array();
         $max_count = count($style);
         for ($i = 0; $i < $max_count; $i++) {
             if (isset($this->color_lst[$style[$i]])) {
                 $style_lst[] = $this->color_lst[$style[$i]];
             }
         }
         imagesetstyle($this->img, $style_lst);
     }
     if (!is_null($brush)) {
         if (!$this->checkImage($brush)) {
             $brush = loadImage($brush);
         }
         if ($brush) {
             imagesetbrush($this->img, $brush);
         }
     }
     return;
 }
示例#13
0
function createThum($image_dic, $image_file_name, $width, $height)
{
    print "Creating Thum<br>";
    $image = loadImage($image_dic . $image_file_name);
    print "Creating Thum<br>";
    $thum = createImageTrueColor($width, $height);
    print "Creating Thum<br>";
    $source_imagex = imagesx($image);
    $source_imagey = imagesy($image);
    imagecopyresized($thum, $image, 0, 0, 0, 0, $width, $height, $source_imagex, $source_imagey);
    print "Creating Thum<br>";
    saveImage($thum, $image_dic . "thum_" . $image_file_name);
    print "Creating Thum<br>";
    return $image_dic . "thum_" . $image_file_name;
}
示例#14
0
                        <td valign="top" width="167"><table border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td height="116"><?php 
    loadImage();
    ?>
</td>
                            </tr>
                            <tr>
                              <td height="116"><?php 
    loadImage();
    ?>
</td>
                            </tr>
                            <tr>
                              <td height="116"><?php 
    loadImage();
    ?>
</td>
                            </tr>
							
                            <tr>
                              <td width="167"><a href="FranchiseeoftheYear.pdf" target="_blank"><img src="images/wingleft_19.gif" alt="" width="167" height="192" border="0" /></a></td>
                            </tr>							
                        </table></td>
                        <td valign="top" width="463">
						<!--content starts-->
							<?php 
    if (!isset($noScroll)) {
        echo "<div id=\"content\" class=\"scroll\">";
    }
    ?>
示例#15
0
<?php

include_once 'procedures.php';
if (isActiveUser()) {
    if (stripos($_SERVER['REQUEST_URI'], 'APimageUpload')) {
        $_SESSION['adminPanelState'] = 'APimageUpload.php';
    }
    $gameList = getGameList();
    if (isset($_POST['submit'])) {
        loadImage($_POST['imagePath'], $_POST['imageType'], $_POST['imageDescription'], $_POST['gameId']);
    }
    ?>

    <script>
        $(window).load(function() 
        { 
            //console.log(document);
            //showModalAlert(document.getElementById('imageDescription'));
            var gameSelector = document.getElementById('gameSelectorDiv');
            gameSelector.style.display = 'none';
        })
    </script>


    <script>
        changeActiveAdminButton('imageUploadButton');
    </script>
    <script>
        function activateGameSelector()
        {
            var typeSelector = document.getElementById('typeSelector');
/**
* exit the script of the ip is recorded as an ip to exclude
* or if the ip is in any range of ip to exclude for this site
* 
* @param int $ip2long ip2long version of ip
* @param string $logo logo name '1.png' necessary if we exit the script
* @param int $idSite
* 
* @return true or calls loadImage() and exit
*/
function exitIfIpExcluded($ip2long, $logo, &$o_site)
{
    printDebug("ip:" . $ip2long);
    // look into the cookie for $a_ipToIgnore
    $a_ipToIgnore = $o_site->getIpArray();
    if (isset($a_ipToIgnore) && sizeof($a_ipToIgnore) >= 1) {
        $i = 0;
        // is the ip excludable ?
        while ($i < sizeof($a_ipToIgnore)) {
            $ip1 = $a_ipToIgnore[$i][0];
            $ip2 = $a_ipToIgnore[$i][1];
            if ($ip2long >= $ip1 && $ip2long <= $ip2 || $ip2long == $ip1 || $ip2long == $ip2) {
                printDebug("<b>=> Ip is excluded, exit</b><br>");
                redirectToUrlIfNecessary();
                loadImage($logo, $o_site->getId());
            }
            $i++;
        }
    }
    printDebug("<b>=> Ip is not excluded</b><br>");
    return true;
}