T.ex.
$filename = 'bilder/bild.jpg';
$im_src = imagecreatefromjpeg($filename);
$src_w = imagesx($im_src);
$src_h = imagesy($im_src);
$dst_w = $src_w + 100;
$dst_h = $src_h;
$im_dst = imagecreatetruecolor($dst_w, $dst_h);
imagecopyresampled($im_dst, $im_src, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
header("content-type: image/jpeg");
header("Content-Disposition: inline; filename=wide_$filename");
imagejpeg($im_dst, '', 95);
imagedestroy($im_src);
imagedestroy($im_dst);
Vill du ha kantlinjer till höger och vänster så går det att göra så här:
$filename = 'bilder/bild.jpg';
$im_src = imagecreatefromjpeg($filename);
$src_w = imagesx($im_src);
$src_h = imagesy($im_src);
$dst_w = $src_w + 100 + 4;
$dst_h = $src_h;
$im_dst = imagecreatetruecolor($dst_w, $dst_h);
$red = imagecolorallocate($im_dst, 255, 0, 0);
imagefill($im_dst, 0, 0, $red);
imagecopyresampled($im_dst, $im_src, 2, 0, 0, 0, $dst_w - 4, $dst_h, $src_w, $src_h);
header("content-type: image/jpeg");
header("Content-Disposition: inline; filename=wide_$filename");
imagejpeg($im_dst, '', 95);
imagedestroy($im_src);
imagedestroy($im_dst);
Vill du ha en border runt bilden kan du göra så här:
$filename = 'bilder/bild.jpg';
$im_src = imagecreatefromjpeg($filename);
$src_w = imagesx($im_src);
$src_h = imagesy($im_src);
$dst_w = $src_w + 100 + 4;
$dst_h = $src_h + 4;
$im_dst = imagecreatetruecolor($dst_w, $dst_h);
$blue = imagecolorallocate($im_dst, 0, 0, 255);
imagefill($im_dst, 0, 0, $blue);
imagecopyresampled($im_dst, $im_src, 2, 2, 0, 0, $dst_w - 4, $dst_h - 4, $src_w, $src_h);
header("content-type: image/jpeg");
header("Content-Disposition: inline; filename=wide_$filename");
imagejpeg($im_dst, '', 95);
imagedestroy($im_src);
imagedestroy($im_dst);