Solved

Image manipulation and PHP

Posted on 2009-04-11
7
291 Views
Last Modified: 2012-05-06
I have 2 images:

image1.jpg (650 x 300 px)
image2.jpg (10 x 10 px)

Basically I want PHP to place image2.jpg over the top of image1.jpg, in a certain place (e.g. 100w, 100h), then save the whole thing as a JPEG.

Any ideas how I can about doing this?

Many thanks.
0
Comment
Question by:DReade83
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24122620
http://us2.php.net/manual/en/function.imagecopymerge.php should get you started.  Can you please post the code you have so far?  Thanks, ~Ray
0
 

Author Comment

by:DReade83
ID: 24122626
I haven't any code just yet. Is it possible to add some text over the top of the second image, and then save the whole thing as one image?
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 total points
ID: 24122658
Yes, you can stack text or other images on top of a background image.  That function above does it for image stacking.  The imagestring() or imagestringup() functions can do it for text.  Then you can create the file with imagejpeg() and you're done.  There is a lot to be found in the GD functions for PHP.

Have a quick read of the functions on this page, and you will find almost everything you could desire!
http://us2.php.net/manual/en/ref.image.php

HTH, ~Ray
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:DReade83
ID: 31569202
Thanks Ray! :-)
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 24122685
Thanks for the points.  Here is a little code snippet that shows what I do to create a little image of a "captcha" number string.  If you look up the functions in the top part, you will get the gist of it quickly.

Cheers, ~Ray
<?php // CAPTCHA_NUMBER.PHP GENERATES A PICTURE OF A NUMBER
 $data	= base64_decode($_GET['dt']);
 $im	= imagecreate(46,13);
 $bg	= imagecolorallocate($im, 255,255,255);
 $gray	= imagecolorallocate($im, 188,188,188);
 $text	= imagecolorallocate($im, 178,34,34);  // firebrick
 imagestring($im,5,4,0,$data,$text);
 imageline($im,4,12,38,0,$gray);
 imagepng($im);
 imagedestroy($im);
?>
 
 
 
 
 
 
<html> <!-- GOES IN THE FORM SCRIPT -->
Type
<img style="display:inline;" src=captcha_number.php?dt=<?php $x = mt_rand(1000,10000); echo base64_encode($x);?> />
here:
<input type=hidden name='_newMd5' value="<?=md5($x)?>" />
&nbsp;
<input name="_newCode" type="text" maxlength="64" size="6" autocomplete="off" />
 
 
 
 
 
 
 
<?php // GOES IN THE ACTION SCRIPT
$newCode	= $_POST["_newCode"];
$newMd5		= $_POST["_newMd5"];
$newCode	= md5($newCode);
if ($newCode != $newMd5)
{
	die('Security code number did not match');
}

Open in new window

0
 

Author Comment

by:DReade83
ID: 24122694
Nice! I'll have a go! Thanks mate!
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 24122696
'Welcome!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question