LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-01-2007, 09:24 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
PHP - how can you combine two images into one?


I want to create a single image out of two images. the new image would just be the two original images sitting right next to one another.

I can do it with a script that runs imagemagick, but I bet there's a way to do it in php without using an external program. Anyone know?
 
Old 06-02-2007, 02:00 AM   #2
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
Have you tried imagecopy() ?
 
Old 06-02-2007, 02:13 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,450

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi

Why not make a simple table with two columns and put the images next to each other? If you set cellspacing and cellpadding to 0, the images will be next to one another.

If that's not what you want, you can use gdlib. Here is some pseudocode:

$img1 = ImageCreateFrom...('picture1');
$img2 = ImageCreateFrom...('picture2');
$both = ImageCreate($new_width, $new_height);
ImageCopy($both,$img1,0,0,0,0,$img1_width,$img1_height);
ImageCopy($both,$img2,$img1_width,0,0,0,$img2_width,$img2_height);
header("Content-type: image/jpeg");
ImageJPG($both);

As you can see, it'll be hard to code without some assumptions. What format are the images? Are they the same height? Anyway it shouldn't be very hard to code, just look in the manual about the ImageCopy... functions.
 
Old 06-02-2007, 02:00 PM   #4
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by Guttorm
Hi

Why not make a simple table with two columns and put the images next to each other? If you set cellspacing and cellpadding to 0, the images will be next to one another.

If that's not what you want, you can use gdlib. Here is some pseudocode:

$img1 = ImageCreateFrom...('picture1');
$img2 = ImageCreateFrom...('picture2');
$both = ImageCreate($new_width, $new_height);
ImageCopy($both,$img1,0,0,0,0,$img1_width,$img1_height);
ImageCopy($both,$img2,$img1_width,0,0,0,$img2_width,$img2_height);
header("Content-type: image/jpeg");
ImageJPG($both);

As you can see, it'll be hard to code without some assumptions. What format are the images? Are they the same height? Anyway it shouldn't be very hard to code, just look in the manual about the ImageCopy... functions.
I was thinking imagecopy may be the way to go, I was just having a brain fart about how you would reallocate the size of the result image each time you pasted an image into it.... but, obviously, you just figure your size beforehand.

I can't use a table because the result needs to be an exact width, but the source images are of varying sizes - I'd never be able to get the correct width without somehow manipulating the images themselves.

thanks for the help.
 
Old 06-03-2007, 08:59 AM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Study these commands:
imagecopy
imagecopyresized
imagecopymerge
imagesx
imagesy
imageinterlace
imagecreatefromjpeg
imagecreatefrompng

There are other commands, but these'll point you to those.

Beyond that you might find that ImageMagick is an easier way to go.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
view .php images ggeo Debian 3 03-21-2007 06:26 PM
PHP & GD Library - Combine Two Images wh33t Programming 1 11-29-2005 09:12 AM
Combine CD images to create a DVD image? purelithium Mandriva 8 11-28-2005 07:43 AM
Images in PHP Napalm Llama Programming 5 04-06-2005 08:17 AM
changing images in php devit Programming 0 04-04-2004 11:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration