function imageresize(&$img, $width, $height) {
$w = imagesx($img);
$h = imagesy($img);
$ratio = 0;
if($width && $height) {
$w_dest = $width;
$h_dest = $height;
} else {
if(is_numeric($width) && $width > 0)
$ratio = $w / $width;
elseif(is_numeric($height) && $height > 0)
$ratio = $h / $height;
if($ratio > 0) {
$w_dest = round($w / $ratio);
$h_dest = round($h / $ratio);
}
}
if(!$w_dest || !$h_dest)
return false;
$new_img = imagecreatetruecolor($w_dest, $h_dest);
imagefilledrectangle($new_img, 0, 0, $w_dest, $h_dest, imagecolorallocatealpha($new_img, 255, 255, 255, 127));
imagecopyresampled($new_img, $img, 0, 0, 0, 0, $w_dest, $h_dest, $w, $h);
$img = $new_img;
}
использование:
$img = imagecreatefrompng('1.png');
imageresize($img, 50, 50); // 50x50
или, чтобы другая сторона рассчиталась автоматически:
imageresize($img, false, 50);
imageresize($img, 50, false);
ARTEMON, см. функции imagejpeg, imagegif или imagepng. ну и заголовок отдать надо с нужным типом.
04 Апр 2012, 18:17Использую __autoload(). Есть некая группа классов ( http://xbb.uz ), которая с ней конфликтует. Как исправить это, не вмешиваясь в них?
04 Апр 2012, 18:38luethus, да, СПС
---
Еще вопрос: написал класс-пагинатор. И при его инициализации по непонятной причине стала показываться лишняя строка, а в html-коде ничего лишнего нету, wtf? (скрин прикрепен)
Класс:
[php:1:302cebe1ff]
<?php
class Paginator {
protected $pagesCount; //Страниц всего
protected $page = 1; //Текущая страница
protected $pagesResult; //Хз че
function __construct($count){
global $itemsPerPage;
if (isset ($_GET['page']))$this->page = (int) $_GET['page'];
$this->pagesCount = ceil($count / $itemsPerPage);
if ($_GET['page'] === 'last')
$this->page = $this->pagesCount;
$this->itemsStart = $itemsPerPage * ($this->page - 1);
$this->itemsEnd = $this->itemsStart + $itemsPerPage;
}
function getLimit(){
global $itemsPerPage;
return $this->itemsStart.','.$itemsPerPage;
}
function display($get="?"){
if ($this->pagesCount > 1)
{
$c = 0;
for($i = $this->page - 2; $i < $this->page + 5; $i++)
{
if ($i > $this->pagesCount)
break;
if ($i > 0)
{
if ($i == $this->page)
$p[] = "<span class='pagelist'><b>$i</b></span>";
else
$p[] = "<span class='pagelist'><a href='{$get}page=$i'>$i</a></span>";
}
else
$c++;
}
$c = $i + $c;
for($i = $i; $i < $c; $i++)
{
if ($i > $this->pagesCount)
break;
$p[] = "<span class='pageListingButton'><a href='{$get}page=$i'>$i</a></span>";
}
echo '<div class="pageListing">Страницы: '.($this->page - 6 > 1 ? "<span class='pageListingButton'><a href='{$get}page=1'>1</a></span> ... " : null).' '.implode($p, ', ').' '.($this->page + 4 < $this->pagesCount ? " ... <span class='pageListingButton'><a href='{$get}page=$pagesCount'>$pagesCount</a></span>" : null).'</div>';
}
}
}
?>
[/php:1:302cebe1ff]
Страница:
[php:1:302cebe1ff]
<?php
include 'system/cms.php';
newDoc("Пользователи");
$pages=new Paginator(myResult("select count(*) from `users`;"));
$q=mysql_query("select * from `users` order by `id` desc limit {$pages->getLimit()}");
$i=0;
while($profile=mysql_fetch_array($q)){
echo "<div class='item".($i%2)."'><a href='/Profile/$profile[id]/'><b>$profile[login]</b></a><br/>Регистрация: ".getTime($profile['reg_timestamp'])."</div>";
$i++;
}
$pages->display();
endDoc();
?>
[/php:1:302cebe1ff]
Okula, пишет MySQL вернула пустой результат (т.е. ноль строк). ( запрос занял 0.0025 сек. )
04 Апр 2012, 21:40Этот запрос и не должен ничего возвращать, он только создаёт таблицу в базе.
04 Апр 2012, 21:57