|
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
|