![]() |
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 |
|
hiya,
i need the watermark to be permanent thanks |
bump for anyone who knows a bit of imagemagick :)
|
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. |
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 |
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. |
woah dude, thanks :thumbsup
|
All times are GMT -7. The time now is 12:42 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123