![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
|
New Webmasters ask "How-To" questions here. This is where other fucking Webmasters help. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Apr 2007
Location: UK
Posts: 1,987
|
Add watermark and resize image PHP script?
Hiya,
anyone know where i can get a simple (and free) PHP script that will Take the image that a user uplaods Add an alpha transparency watermark resize it to a fixed size and then pass it back to my script to insert it into the database Ive done a fair bit of googling on this but come up with nothing. I understand it'll need to use imagemagic. Thanks guys
__________________
ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]
|
![]() |
![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Sep 2005
Posts: 794
|
|
![]() |
![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Apr 2007
Location: UK
Posts: 1,987
|
hiya,
i need the watermark to be permanent thanks
__________________
ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]
|
![]() |
![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Join Date: Apr 2007
Location: UK
Posts: 1,987
|
bump for anyone who knows a bit of imagemagick
![]()
__________________
ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]
|
![]() |
![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: May 2004
Posts: 886
|
Here's the docs for the imagemagick command line tools. If had a bit more time I'd actually get into the php api to see what they have.
http://www.imagemagick.org/script/composite.php Im pretty sure you can also use the GD libs in php to get this done. |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#6 |
Registered User
Join Date: Jun 2007
Location: Vancouver, BC
Posts: 6
|
Standalone using php
I was interested in this topic also.
This code snippet will resize an image. (Remarkable what a pain in the ass such a basic operation is.) See below the example for combining images of different sizes or writing text directly to an image. If you want to save the image you can add a path to imagejpeg (see ca3.php.net/manual/en/function.getimagesize.php for another similar example). <?php $upload = $_FILES['img']; if ($upload['type'] != 'image/jpeg') die("only jpeg files are supported not {$upload['type']}!"); $resize_pct = $_REQUEST['resize_pct']; if ($resize_pct < 0 or $resize_pct > 100) die("bad resize value $resize_pct!"); $img = imagecreatefromjpeg($upload['tmp_name']); if (!$img) die('error processing image'); $dims = getimagesize($upload['tmp_name']); $newx = sprintf('%d',$dims[0] * $resize_pct / 100); $newy = sprintf('%d',$dims[1] * $resize_pct / 100); $newimg = imagecreatetruecolor($newx,$newy); imagecopyresampled($newimg,$img,0,0,0,0,$newx,$new y,$dims[0],$dims[1]); # test output header("content-type: image/jpeg"); imagejpeg($img); -------------------------------------------------------- If you are using the same watermark or have a watermark graphic your best bet is to combine the images together. ca3.php.net/manual/en/function.imagecopymerge.php Has example. If you want to use truetype or postscript fonts (requires external libraries). ca3.php.net/manual/en/function.imagettftext.php ca3.php.net/manual/en/function.imagepstext.php A more bare bones approach could use the imagechar or imagestring functions. ca3.php.net/manual/en/function.imagechar.php ca3.php.net/manual/en/function.imagestring.php |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#7 |
Registered User
Join Date: Jun 2007
Location: Vancouver, BC
Posts: 6
|
minor correction
it should read imagejpeg($newimg) at the end of the code snippet.
to write to a file remove the header("content-type: image/jpeg"); and change imagejpeg($newimg) to imagejpeg($newimg,"some/image/path"); you'd want to do any other transformations after the imagecopyresampled function. |
![]() |
![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
Join Date: Apr 2007
Location: UK
Posts: 1,987
|
woah dude, thanks
![]()
__________________
ICQ: 446-568-913 Email: liam||goodingsmedia.com msn: [email protected]
|
![]() |
![]() ![]() ![]() ![]() |