php - granted - symfony login roles
Postal personalizada de PHP (2)
Estoy creando una nueva función en mi sitio que permite a las personas enviar postales a amigos. en esta sección pueden elegir la imagen que desean enviar (ya han subido la imagen a su perfil -> sección de mis imágenes)
Estoy usando la función php para crear el texto que va a la derecha, pero ¿cómo puedo agregar otra imagen a esta imagen con el texto?
Utilizo imagettftext
para crear el texto, imagecreatefromjpeg
para abrir la imagen principal (ver más abajo) e imagedestroy
cuando imagedestroy
Gracias
Estoy usando esta postal:
Primero tendrás que recortar la imagen para que quepa en tu postal. Basado en tu imagen, esto es lo que tienes que hacer:
<?php
$sourceImage = ''./postcard-template.jpg'';
$uploadedImage = ''/path/to/image/hong-kong2.jpg''; // let''s get hong kong as example
$mime = '''';
$font = ''/path/to/font/arial.ttf'';
function CroppedThumbnail($source, $width, $height, &$mime) {
$data = getimagesize($source);
$sourceWidth = $data[0];
$sourceHeight = $data[1];
$mime = $data[''mime''];
$image = imagecreatefromjpeg($source);
$sourceRatio = $sourceWidth/$sourceHeight;
if (($width/$height) > $sourceRatio) {
$newHeight = $width/$sourceRatio;
$newWidth = $width;
}
else {
$newWidth = $height*$sourceRatio;
$newHeight = $height;
}
$croppedImage = imagecreatetruecolor(round($newWidth), round($newHeight));
imagecopyresampled($croppedImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $sourceWidth, $sourceHeight);
$thumb = imagecreatetruecolor($width, $height);
imagecopyresampled($thumb, $croppedImage, 0, 0, (($newWidth/2)-($width/2)), (($newHeight/2)-($height/2)), $width, $height, $width, $height);
imagedestroy($croppedImage);
imagedestroy($image);
return $thumb;
}
// Create the cropped image first
$newThumb = CroppedThumbnail($uploadedImage,240,315, $mime);
switch($mime) {
case ''image/gif'':
$image = imagecreatefromgif($sourceImage);
break;
case ''image/jpeg'':
$image = imagecreatefromjpeg($sourceImage);
break;
case ''image/png'':
$image = imagecreatefrompng($sourceImage);
break;
default:
// error or stop script
break;
}
$message = "this is some text/nsome other text/ntext text";
imagettftext($image, 21, 0, 320, 255, imagecolorallocate($image, 0, 0, 0), $font, $message);
imagecopy($image, $newThumb, 40, 40, 0, 0, 240, 315);
header(''Content-Type: image/jpeg'');
imagejpeg($image);
imagedestroy($image);
Por ejemplo, yo uso esta imagen (necesita ser recortada):
entonces saldrá:
Use imagecopymerge para copiar la foto en la tarjeta postal
bool imagecopymerge ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h , int $pct )