Модераторы: Aliance, skyboy, MoLeX, ksnk
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Как разделить картинку на 2 части 
:(
    Опции темы
apostolnikolai
Дата 23.6.2018, 20:26 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 152
Регистрация: 19.3.2009

Репутация: нет
Всего: нет



Здравствуйте! 

Подскажите как на PHP можно разделить один графический файл на два, ровно по середине?

Вот вариант кода, который это делает, но он чуть обрезает картинки на выходе и вырезанное закрашивает черным. Подскажите что не так 

Код

$padding=10;
$info = getimagesize("files/upload/1_1.jpg");
$width=$info[0];
$height=$info[1];

$canvasWidth=$width+4*$padding;
$canvasHeight=$height+2*$padding;

$output = imagecreatetruecolor($canvasWidth, $canvasHeight);
//$background = imagecolorallocate($output, 255, 255, 255);
imagefill($output, 0, 0, $background);

$output1 = imagecreatetruecolor($canvasWidth, $canvasHeight);
//$background = imagecolorallocate($output, 255, 255, 255);
imagefill($output, 0, 0, $background);

$orig = imagecreatefromjpeg("files/upload/1_1.jpg");

imagecopy($output, $orig,$padding, $padding, 0, 0, $width/2, $height);

imagecopy($output1, $orig,2*$padding+$width/2, $padding, $width/2, 0, $width/2, $height);

imagejpeg($output,"files/upload/ram/str.1.jpg");

imagejpeg($output1,"files/upload/ram/str.2.jpg");

PM MAIL   Вверх
Vardoulacha
Дата 24.6.2018, 05:39 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 183
Регистрация: 11.8.2005

Репутация: нет
Всего: 8



Если я с утра правильно вижу ))

1. обрезает из-за паддингов, зачем они там вообще?

2. черным красит потому что неправильный размер канвы $canvasWidth а надо $width/2

P.S. зачем вот это вот все $canvasWidth=$width+4*$padding; ? из-за этого все лаги с обрезанием
PM MAIL   Вверх
apostolnikolai
Дата 24.6.2018, 11:25 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 152
Регистрация: 19.3.2009

Репутация: нет
Всего: нет



Если Вас не затруднит можете поправить код! я с php очень плоха дружу.
PM MAIL   Вверх
apostolnikolai
Дата 24.6.2018, 12:01 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 152
Регистрация: 19.3.2009

Репутация: нет
Всего: нет



С левой стороной разобрался 
Код


$padding=10;
$info = getimagesize("files/upload/1_1.jpg");
$width=$info[0];
$height=$info[1];

$canvasWidth=$width;
$canvasHeight=$height;

$output = imagecreatetruecolor($canvasWidth/2, $canvasHeight);
//$background = imagecolorallocate($output, 255, 255, 255);
imagefill($output, 0, 0, $background);

$orig = imagecreatefromjpeg("files/upload/1_1.jpg");

imagecopy($output,    $orig,    0,    0,    0,            0, $width/2, $height);


Добавлено через 1 минуту и 20 секунд
А вот правую сторону как пока не выходит

Код

$padding=10;
$info = getimagesize("files/upload/1_1.jpg");
$width=$info[0];
$height=$info[1];

$canvasWidth=$width;
$canvasHeight=$height;

$output1 = imagecreatetruecolor($canvasWidth, $canvasHeight);
//$background = imagecolorallocate($output, 255, 255, 255);
imagefill($output, 0, 0, $background);

$orig = imagecreatefromjpeg("files/upload/1_1.jpg");



imagecopy($output1, $orig,    0,     0,    $width/2,    0, $width/2, $height);


Добавлено через 8 минут и 35 секунд
Все разобрался! Вот рабочий код если кому надо :

Код

$padding=10;
$info = getimagesize("files/upload/1_1.jpg");
$width=$info[0];
$height=$info[1];

$canvasWidth=$width/2;
$canvasHeight=$height;

$output = imagecreatetruecolor($canvasWidth, $canvasHeight);
//$background = imagecolorallocate($output, 255, 255, 255);
imagefill($output, 0, 0, $background);

$output1 = imagecreatetruecolor($canvasWidth, $canvasHeight);
//$background = imagecolorallocate($output, 255, 255, 255);
imagefill($output, 0, 0, $background);

$orig = imagecreatefromjpeg("files/upload/1_1.jpg");

imagecopy($output,    $orig,    0,    0,    0,            0, $width/2, $height);

imagecopy($output1, $orig,    0,     0,    $width/2,    0, $width/2, $height);

//imagecopy($output, $orig,3*$padding+2*$width/3,$padding, 2*$width/3, 0, $width/3, $height);

imagejpeg($output,"files/upload/ram/str.1.jpg");

imagejpeg($output1,"files/upload/ram/str.2.jpg");



ВСЕМ СПАСИБО !!!!

PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | PHP: Графика | Следующая тема »


 




[ Время генерации скрипта: 0.1066 ]   [ Использовано запросов: 21 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.