imnewtophp Posted October 19, 2012 Share Posted October 19, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/269690-resize-image/ Share on other sites More sharing options...
johnnyd1963 Posted October 19, 2012 Share Posted October 19, 2012 (edited) 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 October 19, 2012 by johnnyd1963 Quote Link to comment https://forums.phpfreaks.com/topic/269690-resize-image/#findComment-1386397 Share on other sites More sharing options...
requinix Posted October 19, 2012 Share Posted October 19, 2012 imagecopymerge() does not resize. Try imagecopyresampled instead. Quote Link to comment https://forums.phpfreaks.com/topic/269690-resize-image/#findComment-1386405 Share on other sites More sharing options...
imnewtophp Posted October 19, 2012 Author Share Posted October 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269690-resize-image/#findComment-1386411 Share on other sites More sharing options...
johnnyd1963 Posted October 19, 2012 Share Posted October 19, 2012 try to make $src = imagecreatefromjpeg('tiffany_alvord_heart_2bg9s7p.sized.jpg'); into $src = imagecreatefromjpeg('tiffany_alvord_heart_2bg9s7p.sized.JPG'); look at the difference jpg or JPG Quote Link to comment https://forums.phpfreaks.com/topic/269690-resize-image/#findComment-1386427 Share on other sites More sharing options...
requinix Posted October 19, 2012 Share Posted October 19, 2012 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"Ó€E7qÑ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ÝJDŸ£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žxjѧ¨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Û>5DPJ(¨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Ý,5FzTBY–¨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:bg^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. Quote Link to comment https://forums.phpfreaks.com/topic/269690-resize-image/#findComment-1386468 Share on other sites More sharing options...
imnewtophp Posted October 20, 2012 Author Share Posted October 20, 2012 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/269690-resize-image/#findComment-1386548 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.