Autor Zpráva
ses56g
Profil *
ahoj, pls. jak mam udelat aby php skript nacetl dva obrazky png (vetsi a mensi) a ten mensi vystredil doprostred toho vetsiho (samozrejmne aby mensi byl pres vetsi)

:D pomuze mi nekdo?
ses56g
Profil *
aby zobrazil jedno png..
bitbit
Profil
Zkus si poupravit toto:



<?php
header("Content-type: image/jpeg");
$im = imagecreate(100, 100);
$w = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);

/* Draw a dashed line, 5 red pixels, 5 white pixels */
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w);
imagesetstyle($im, $style);
imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED);

/* Draw a line of happy faces using imagesetbrush() with imagesetstyle */
$style = array($w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $red);
imagesetstyle($im, $style);

$brush = imagecreatefrompng("http://www.libpng.org/pub/png/images/smile.happy.p ng");
$w2 = imagecolorallocate($brush, 255, 255, 255);
imagecolortransparent($brush, $w2);
imagesetbrush($im, $brush);
imageline($im, 50, 50, 50, 50, IMG_COLOR_BRUSHED);

imagejpeg($im);
imagedestroy($im);
?>


je to plně funkční.

A aby to nevypadalo že se chlubím cizým peřím tak od tud to pochází
http://livedocs.coggeshall.org/en/function.imagesetstyle.html


Jen jsem uprvil, aby se ten druhy obrázek okládal do středu.
bitbit
Profil
samozřejmě si místo vytvoření obrázku načteš ten větší, zjistíš si jeho rozměry, vydělíš dvěma. A místo
imageline($im, 50, 50, 50, 50, IMG_COLOR_BRUSHED); dáš to samé jen místo 50 budou ty hodnoty vydělené dvěma. jak sem pochopyl tak je to pozice kde bude střed druhého obrázku, takže tam musíš zadat střed prvního obrázku ( to je v tvém případě ).
bitbit
Profil
Takže něco takovýhleho:


<?php
header("Content-type: image/jpeg");
$im = imagecreatefrompng(" http://i.iinfo.cz/urs/png4_3-115934600282467.png ");


$width = imagesx($im);
$height = imagesy($im);


$stredy = $height / 2;
$stredx = $width / 2;

$brush = imagecreatefrompng(" http://www.libpng.org/pub/png/images/smile.happy.png ");
$w2 = imagecolorallocate($brush, 255, 255, 255);
imagesetbrush($im, $brush);
imageline($im, $stredx, $stredy, $stredx, $stredy, IMG_COLOR_BRUSHED);

imagejpeg($im);
imagedestroy($im);
?>



místo těch url budeš dávat umístění těch tvých obrázků.

Mělo by to být dobrý. Jen bys to mněl ošetřit proti špatným typům obrázků atd. Toto je pouze na png jen sem neupravoval výstup ten je v jpeg.

A tady to můžete z číhnout :D
http://zlord.d1net.cz/pokus/pngvpng.php
bitbit
Profil
Jen bych chtěl dodat, že na třeba na wz.cz to nejede :( takže jsem to musel dát na prof. hosting
ses56g
Profil *
[pre]<?php
// Ten vetsi
$filename = "/".AddSlashes($_GET["file"])."";
// Set a maximum height and width
$width = 300;
$height = 300;
$im = imagecreate($width, $height);
// Content type
$yuo = explode('.',$filename);
header('Content-type: image/png');
if($yuo[1] == 'jpg' OR $yuo[1] == 'jpeg' OR $yuo[1] == 'JPG' OR $yuo[1] == 'JPEG'){
$action='imagecreatefromjpeg';
}
if($yuo[1] == 'png'){
$action='imagecreatefrompng';
}
if($yuo[1] == 'gif'){
$action='imagecreatefromgif';
}
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if(($width_orig > $width) OR ($height_orig > $height)):
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
else:
$width = $width_orig;
$height = $height_orig;
endif;

// Resample
$brush_p = imagecreatetruecolor($width, $height);
$brush = $action($filename);

imagecopyresampled($brush_p, $brush, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

$brush_d = imagecreatefrompng("mensi.png");
$color = imagecolorallocate($brush_d,255,255,255);
$font = './verdana.ttf';
imagettftext($brush_d, 20, 0,70, 35, $color, $font,"".AddSlashes($_GET["text"])."") ;



$w = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);

/* Draw a dashed line, 5 red pixels, 5 white pixels */
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w);
imagesetstyle($im, $style);
imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED);

/* Draw a line of happy faces using imagesetbrush() with imagesetstyle */
$style = array($w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $red);
imagesetstyle($im, $style);


$w2 = imagecolorallocate($brush, 255, 255, 255);
imagecolortransparent($brush_d, $w2);
imagesetbrush($brush_d, $brush);
imageline($im,0, 100, 100,100, IMG_COLOR_STYLEDBRUSHED);

imagejpeg($im);
imagedestroy($im);


?>

jak tohle mam predelat:tenhle skript zmensi obrazek na 300px x 300px a potom pokracuje vkladani druheho coz nejde...
bitbit
Profil
A ty chces aby se to zmenšilo nebo ne?
ses56g
Profil *
dobry nic, moc dekuji za pomoc, uz to jde
bitbit
Profil
Nemáš zač :D

Jsem rád že jsem pomohl.
Toto téma je uzamčeno. Odpověď nelze zaslat.

0