Jump to content

Resize Image


imnewtophp

Recommended Posts

I have a page that merges two pictures into one using the code below. I am trying to rezise the $src image. At the minute the last two numbers in imagecopymerg resizes what is displayed but it shows only part of the image and doesn't resize the image, for example it would show the top corner of the image.

 

<?php
$dest = imagecreatefrompng('polayoloright.png');
$src = imagecreatefromjpeg('tiffany_alvord_heart_2bg9s7p.sized.jpg');
imagealphablending($dest, false);
imagesavealpha($dest, true);
$src = imagecreatetruecolor(50,50);
imagecopymerge($dest, $src, 1, 1, 0, 20, 50, 50, 100);
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>

 

 

I have tried adding the following. It resizes it but displays a black box, not the image.

$src = imagecreatetruecolor(50,50);

 

Any ideas?

 

Thanks

Link to comment
Share on other sites

You need something like this ?

 

if ($_FILES['foto_mijzelf']['type'] == "image/pjpeg" || $_FILES['foto_mijzelf']['type'] == "image/jpeg" || $_FILES['foto_mijzelf']['type'] == "image/jpg")
{





$uploaded_foto_mijzelf = $_FILES['foto_mijzelf']['tmp_name'];
$imagesize = $_FILES['foto_mijzelf']['size'];
$imagetype_persoon = $_FILES['foto_mijzelf']['type'];
$image_file_mijzelf=$_FILES['foto_mijzelf']['name'];
// haal foto maten
list($width, $height) = getimagesize($_FILES['foto_mijzelf']['name']);

$imgwidth= $width;
$imgheight=$height;
$a = ($imgwidth/100);
$imageheightpercent= (100/$a);
$onePerrcentImgheight=$imgheight/100;
$newImgHeight=$onePerrcentImgheight*$imageheightpercent;
$imgwidth= $width;
$imgheight=$height;
$b = ($imgwidth/100);
$imagewidthpercent= (100/$B);
$onePerrcentImgwidth=$imgwidth/100;
$newImgWidth=$onePerrcentImgwidth*$imagewidthpercent;

$slides="images";
$thumbs="thumbs";
$new_height1=$newImgWidth;
$new_width1=66;
$new_height=$newImgHeight;
$new_width=100;

chdir ($structurec);
chdir ($location_thumb_persoon);
//if width smaller then height
if ($width<=$height){




$src = imagecreatefromjpeg($uploaded_foto_mijzelf);
$tmp1=imagecreatetruecolor($new_width1,$new_height1);
imagecopyresampled($tmp1,$src,0,0,0,0,$new_width1,$new_height1, $width,$height);
imagejpeg($tmp1,$image_file_mijzelf,100);
imagedestroy($src);
imagedestroy($tmp1);
}


//if width bigger then hight
if ($width>=$height){

$src = imagecreatefromjpeg($uploaded_foto_mijzelf);
$tmp1=imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($tmp1,$src,0,0,0,0,$new_width,$new_height, $width,$height);
imagejpeg($tmp1,$image_file_mijzelf,100);
imagedestroy($src);
imagedestroy($tmp1);

}
}

Edited by johnnyd1963
Link to comment
Share on other sites

You need something like this ?

 

I saw that code from searching earlier. Which part exactly do I need to use. I am not uploading the pictures they are already uploaded.

 

 

imagecopymerge() does not resize. Try imagecopyresampled instead.

 

I have tried your suggestion

 

$src = imagecopyresampled(50,50);

 

It doesn't work.. it does the following: http://pennybeta2.webege.com/merge.php

 

Thanks for your help guys.

Link to comment
Share on other sites

I have tried your suggestion

 

$src = imagecopyresampled(50,50);

 

It doesn't work..

I gave you a link so that you would click it, read the documentation, and use the function correctly.

 

And your script is outputting HTML.

<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table><br />
<b>Warning</b>:  imagecreatefromjpeg(tiffany_alvord_heart_2bg9s7p.sized.JPG) [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: failed to open stream: No such file or directory in <b>/home/a4566300/public_html/merge.php</b> on line <b>3</b><br />
<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' size='1' color='#000000'>Free Web Hosting</font></a></div></td></tr></table><br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table><br />
<b>Warning</b>:  Wrong parameter count for imagecopyresampled() in <b>/home/a4566300/public_html/merge.php</b> on line <b>10</b><br />
<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' size='1' color='#000000'>Free Web Hosting</font></a></div></td></tr></table><br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table><br />
<b>Warning</b>:  imagecopymerge(): supplied argument is not a valid Image resource in <b>/home/a4566300/public_html/merge.php</b> on line <b>12</b><br />
<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' size='1' color='#000000'>Free Web Hosting</font></a></div></td></tr></table>‰PNG


IHDR   ê   ù   )Ö©{  °IDATxœíÝÿqÛFÆñGÿm(
˜p"Ó€E7qÑ5p7×@n’\Â9×€“4`(
˜JÒ@¤4 û"½\.°øµ‹ñýÌp0”‰$zòòÅ,.À奤¤Ëç罟%ý{g.b ;ˆ_ËLÛÃó{£"¨8W}ƒØFôܼˆýÀˆÞ<?o5nÛ|îo?ãAEÊÌ JÒ[k;¨õz­ËËKív;=>>ÆøÈZSJ"ˆ›ÍÆù¼wss£Ÿ~úÉüÑ­¨¨8#³¢Ožçáv²%‚Š!&
âjµRžç‡Gß ú8‚úVҏ£}@M’
¢ýˆ…ŠŠ©]©:Jº}Þ^\´ÛíÛ®jìØ—mèý²1G=oû îÇßXÛA¥D×óÝÝÝÉû×ëõQp÷..N¢5;uÞDI*ŠÂù|{{ÛëÏ{zz:y-ÏsÝßß›/]+â‘_¾ú¦ jü úìv;m6ÇçL8‚AÖ¤A̲L›Ífò Ú_ICÑçáááäµ<ÏíýÙŠŠz6’bÝ,1–º1â?;U'Óï$ýemÿ-飤wæþn·Û£?`ê#¿u‚¨$‚X?¬í?[üügA­«¨–¨³T‚Ú앤Üx¼~~^T˲¬}DêÛJ
¢ÏQ2]G}©¨ÓªâþA<Ø
}PUÝJDŸ£d¶¬¨Û`{ãpîエ/³Ä„‚hnG_-ÁáJÒa¨še™3¬ŽYj¦ªÇ
nîA%ˆê>Ô±J;ˆm
O]³ÔÍfcÿûŒ6KMý«ï¤A”¤ëëkI:Ün·K¢$ÏÏŸ¬í¨—{ô 㸃k–ê8Ñ?øqŠ½©ƒšdÍçX\C}‚ÕNFßéúê»ÙlìYêFÒ¯¡wL
T{Ý‚éì‡ýWÑ¥Ñçäȯý;⨨Ñ9ԐHµ’Jí³j&bÝPͼ³TG»­ÿñ• >K`¨OÃòÎRSèQß(þJn’¢¡”{¨OãðÎR§¬¨’þ+é&ÔØëÖLD{~˜PKÅê£Ù+IGCe׈fªYê…ª¯Q½KøXH
•ÐÙ5¥â\%;KõL"ˆç0ÔG³RÆ4¢(Š6G~£„à…¬ùÑû÷ïµÙl¢1¡>AD)ÏØpªYêYG»¤0ýcA”Ž‡ú¶ÒÜhYQ£ÌR_¨Åü¨-û¬NsÃÌüá{ÃTG~O*ªk~´—ÀÙ5Åó3AD¥¹±ÿý6MÝ£¸*jQº¹¹‰qІ¡>¦TúÞ0å,õJÕaé'IOY–=Ù¾ûî»'ó=ŸUUÃ÷’¾—ô­ª“-^Fúgš¼’õ;ëb¿çùç‚z!ë@Škø_–eÛ?¯ÔñPŸŠˆ9i5ï¾¾¾¶Û½¼íÏöõÕóscŸê8
\Hú¤ïT
|WªNžx­jѧ¨ZøéWUý#!Å\”憫OuÈìÇ‘}P½}ª¥TÄÿ©
"gÞà\”æ†+ŽÂ•‡Ú™½¾5µCÀÄŽ~ù›¦ †×avå‹}P?›/¶¨¨yˆð—¹AEÒÔ§¢æAöÄзG•"’&pôËŸJEÝóÎR¯¯¯íÙÑ›†?˜«—Jp–º¯¨ÞYªC>öÎ 	8%ºªê~eCfw*_]šÞѧbA’ëSkƒÚBðCÒÀD’ëS©¨À©äf©fP¯Ås\Þíª ²äf©­+ªãòžxë´ qÍ»GͲÌ~éj̝‘\jò^‹Ç,Ñj–še™‡`…ˬ¨Þ+`èS±'³T×5Ù1ÛÁ¯¬íÒÜ OÅ‚æ†+¨1WcPmŽûf̝REEÒôÉÜhYQƒ.;¨ÌR**¦ÂܘU*1KÅ2M]QmÌR/’™¥Úõd–jŸ•‘ç¹ý–í˜;¤jʪjUòœçè*p®
scÊ>ÕÔÆóA};ꉢ¢iJf–ê
jãµxô¨X***¦Âܘz–j{#ãpóz½>9$½Z­Ñ`	¼ËèÖ,…÷Z<f©Xï,5Fár}õõ®kJŸŠi¼Ý‹§tU¢Oö¼·{‰Q¸ê‚Ê,¨PQðÞ’4Fáª*³T rvõå({¤e¾=ª$­×kû%V{À9J¢¢Öé3Kýv²½Âš|–ZWQ½ëš:Îq¤¢â\M^Uë‚*yÎstœãøõ;$hò>µ)¨G¨¨X°¤+jãµxŽŠÊŠ„8W“ÏR©¨€_inØËèJóêQ%f©8O¥ï
Sžtt]êjµ:9$½^¯¹Ü
Kà]F·æºÔÑ
WSEýÍܸ¿¿?y}*Â{KR)ìI@­{T‰>‹Vš®>5dáòµ07Zô©¯‡î¨Ò÷†…kPEÝn·ö[ò!;$¬47ZVÔÑNòÕ»®©%°/@ÊoI*QQ”æƬzÔ¯zÒ÷†)®zg©,Š…˜t–ꫨÞYªCÞwg€„yoI*…›¥¶éQ¯ OÅ‚4.Q$…ëSÛÕ{-ž…Y*Εw‰¢P}*h¯OEe–Ú&¨Þkñ,yߝ׸Œ®DER0ï5Ë2û¥«þ»$k²µ
ï="™¥b!¼ËèÖÌRŸÔ¦¢þnn<>>ž¼aÊ».yoI*I×××öKùÐn{®ocŸê(÷\@ŽsåíSò¡Ú6¨}ª£¢~Ó—€¤yûÔX©¨@7}*êà“€Úµq–JŠñÎR©¨ÀôæÛ£JÌR±G¿ü®k´§<	ˆY*ðEôYjÛŠÊ,¨áªªcÏR»¬™Tšöš1ô©XÂÜh¹DQ>ä{õd/ßÍ
HUŒ>u´ŠúnV@Bº.£+
œ¥v	j㺦SÞÍ
˜HSan̪G•¤Õje¿Äˆg/µYªw]Sf©Xï,5Ë2;½OêRQ½÷ˆ¤OÅR¹ªê˜#ËN÷ž}*°W˜® ŽyР Ú˜¥b©¨¨@š¼³Ô1TèTf©@¥ñÒOi~u”»Y‰ñ^ú™l*…»›˜¨µ«>³ÔocíY´Yj׊ê½Gä”+…‘E«ª]ƒ*yÖŒ	u7+ AÑúÔ>Am\×”ŠŠ9«ŠÊJ8WÞ[’Ž5KíÔÆuM©¨X³ª¨³Tœ§¨³Ô®ÞÈ8ܼ^¯OI¯×k.wÃx—Ñ­Y:4
ï="™¥bA¼³ÔÕj5¸põùêë½G$}*ÄÛ§Žq±JŸ JÝûÔÁw³åíSǸX¥oPg©S®DVšö…*RÂÕ!ïù9@ê/ý”ÆYP¡oPg©TT,Hin̽¢Jïf$ªô½aʼ³T–ÅBx/ýc–:JE½»»kó3yÏÏRæ]FW¾8}ß žÌRíŝèS± ¥¹¢OíT©ûý7˜¥â\•¾7íS‡õVš©UÔ®÷ˆÌ|²à³T**0\in´¬¨®KÙ£JÌRqžJsÃu¾ï”ªÍRW«³T,•÷ÒÏšYjë†TÔß̍ûûû“7Lyu;‘÷ÒOiØâô£õ¨Òé×ß)W
"óžV;dá¿¡A-Ì
;¨cÞÍ
H\㥟Ұ>•Š
Œ£OEm½8ýР6ÎRéQ± —~JTT óíQ%)Ë2û¥^w³´GŠY*P	:KZQ™¥• ³Ô1zÔÆuMéS± ÁúÔ1‚Ú¸®)³Tœ¡+U-Ü?%}/飪	Hn¾iÌ>õE÷}<qRQÍ+g¨¨˜¡+U¿§›çço¬íVv»Þ½{wôZßYêAý,é°7öÿE¦\
¨1J}\‹'UQMc¬i
t%ˆu²,ÓÍ͍nnnNþž£¢æmþÌ1‚ê½÷Æjµ²¿‘uÄè`ò n6]^^:Ÿ›ô]P!xE•ªªêÝ 5fÄž^ɳìèAýÝÜx||<yCžçº½½5_ÚŠŠºdKâ‘ëëk;¹"Uªªêá_ðn·;ú¦O]œE±‡\žÂ5VPw2Žæ¶8òûVҏ#}6â#ˆl·[WEm4fE=°g©TÔÙ!ˆqy§+¨ÌRç… Nh»Ýê‡~0_Ê}?¬¢í5¶WªþãﯟŸ	bšrßÆìQ˜¥WÄý#(‚8LŸYêXA-Í
«Q®öät–Ê9¿õâò4ÎRÇ
ª÷‘›ÍÆðFÒ¯#}þÜÄ…ë:K+¨RUUóýFQG%~È
l34i¥êAúò5k»ÝÄ´åjhƒÕ6åz1$Dóië:K;¨-*jÊ=*ADl³Ô1ƒÚxÈÄ**AĤºÎRƒVT“£¢JÕ
l'‹B€ "i]ýT—õz­»»;ó¥úÍR	"f­ëEÁ‚ꚥvèS	"Î^–eöe¡W².Ý3¨}f©ÿVUU	"Ç‘‡Úª:fP¥î³Ô­ O‘ºš>ÕÙ

êÉ^Œ8l'ˆ˜»Íf£_~ùÅ|)jE=°+j—«h"Î]—ÅéǪw–úñãG}øðáp…
AÄRu9ò¼¢ÚÞ½{w²z8°D]f©£ÞÈXVP]×¥¨t©¨#öKIGƒ¡ê– \.//íYêZŽYêصÕ="TÚVÕ±ƒ*µ¸G$€JÛ>5DPJ(¨GEf í,5DPÿ27¨¨@=**0m§§G&Ôö´ÚàÕºP€eµZÙ/½±_Tf©@mªjˆ Jô©@kmúÔPA¥OZ¢¢3Ps£ï#¡‚Ê,h‰Š
Ì@2=jY–>˜¿)+êÑJjÖ}QX|³ÔPA=AUêùªjÈ æAêùúT**€)+ê'sƒ õ|³T** GP®K¥Gà»Ñ7H@;%…
*³T ƒõzm¿t¨ªÑ*ªDUš4Ýè;tPsƒ õšúT**GEýzÿ¡ƒÊ,h‰Š
Ì =*0MuìÛ.Ú®$ÖͲŒÕ€'‘Ì$ýº¢ÝçѺ$ KÝ,5FzTBY–¨WקÆêQ2ùêÔ«ëS_Døì“ŠºÝn#|,®²,k–¯¥8Aý,éÝ~ƒŠŠ%h
bÇóÞ§«¨À܍DïGIq‚JŠÙyxxÐn·s>G¼CáÏ’þ%QQ±P‰±x~þdmÿf¿1ô	{OGOOuïF1· úĨ¨RUU¢Ýnç:
´vnAô‰ÔŒuJéSá“HwªŠÌNՍÏÌí“v‡³¢0KAì&VP™¥.PQ'ϱŸÉ**æÏDIº½½µgDŸ˜=êub:bg^I::]ƒÍôâ|Ä
ªÄ,5º‚X?Œ¿&ˆÅúê+UÿòýFQù(á –’þŒµK0YPá·WDÄêUµsÄÝnkÙšRqbõˆŸ•‚ˆ±LZQçŽ "–É‚:	q?ª(E-æx&¹YjBA|Puš¥¹ý{ÃÏaabUŠ<K%ˆ81¿úJ#ÏR#®[s‡ "ŠIƒê}3A$MÔƒ>T/D Qìõ{I?Dü<‚ˆ³0iEIñü|Ý`*sjñüL±X±¿úJÒ{I7ú²*añüL óõ“«wABÅ    IEND®B`‚<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table><br />
<b>Warning</b>:  imagedestroy(): supplied argument is not a valid Image resource in <b>/home/a4566300/public_html/merge.php</b> on line <b>17</b><br />
<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' size='1' color='#000000'>Free Web Hosting</font></a></div></td></tr></table>	
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

Can't do that.

Link to comment
Share on other sites

Thanks,

 

Got it working.

 

<?php
// The file
$src = 'http://s2.evcdn.com/images/block250/I0-001/004/166/985-0.jpeg_/tiffany-alvord-85.jpeg';
$percent = 0.5;


header('Content-Type: image/jpeg');

list($width, $height) = getimagesize($src);
$new_width = 186;
$new_height = 146;


$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($src);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

$dest = imagecreatefrompng('polastraight.png');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopymerge($dest, $image_p, 40, 38.5, 0, 0, 186, 146, 100);

header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.