** کینگ کد : بزرگترین مرجع دانلود سورس کد های برنامه نویسی اندروید، ویندوز و جدید ترین اسکریپت های روز دنیا **
-----------------------------------------------
** سورس فروشگاه اینترنتی مارکیت فارسی برای اندروید - سورس فروشگاه اینترنتی موکتز فارسی برای اندروید **
-----------------------------------------------
** اسکریپت چیست؟ و چگونه از آن استفاده کنیم؟ (آموزش کامل نصب اسکریپت) **
-----------------------------------------------
** (160 جلسه) آموزش کامل و 0 تا 100 برنامه نویسی PHP **
-----------------------------------------------
** دانلود فیلم آموزشی فتوشاپ فارسی **
-----------------------------------------------
» بروزترین سایت ایرانی محصولات کدکنیون ( سایت /https://codemilo.ir )
» Cicool – Page, Form, Rest API and CRUD Generator
» KingArchitect | Property Portfolio & Real Estate React Template – No JQuery
» Sheltos – Real Estate React Next Js with Redux Toolkit , React Hooks & API Routes Template
» Acres – Real Estate React Template
» Mingrand – Real Estate React Template
» ChawkBazar – Elementor Lifestyle and Fashion Ecommerce Theme
» Streamit 3.0 | Video Streaming WordPress Theme + RTL
» MagicAI – OpenAI Content, Text, Image, Chat, Code Generator as SaaS
» PHP Form Generator – Codeigniter 4 Form Master, Form Header Detail, User Management, Multi-language
» بروزترین سایت ایرانی محصولات کدکنیون ( سایت /https://codemilo.ir )
» Cicool – Page, Form, Rest API and CRUD Generator
» KingArchitect | Property Portfolio & Real Estate React Template – No JQuery
» Sheltos – Real Estate React Next Js with Redux Toolkit , React Hooks & API Routes Template
» Acres – Real Estate React Template
» Mingrand – Real Estate React Template
» ChawkBazar – Elementor Lifestyle and Fashion Ecommerce Theme
» Streamit 3.0 | Video Streaming WordPress Theme + RTL
» MagicAI – OpenAI Content, Text, Image, Chat, Code Generator as SaaS
» PHP Form Generator – Codeigniter 4 Form Master, Form Header Detail, User Management, Multi-language
فرض کنید که دو عکس داریم و می خواهیم که آن دو را با یک سری کد، در جهت عمودی، به یکدیگر متصل کنیم. یعنی عکسی ساخته می شود که عکس اول در بالای آن و عکس دوم در پایین آن قرار می گیرد و عرض (width) عکس ترکیب شده، برابر ماکزیمم اندازه عرض آن دو عکس می باشد. برای این منظور، می توانیم از کدهای PHP استفاده کنیم. دقت کنید که در کدهای PHP ، از توابع مربوط به کتابخانه GD استفاده خواهیم کرد که در شماره های جدید PHP وجود دارد، البته خیلی نگران نباشید چون دیگر اکثر سرورها، از جدیدترین نسخه های PHP استفاده می کنند.
فرض کنید که عکس اول (عکسی که در بالا قرار می گیرد) دارای نام image1.png باشد و عکس دوم (عکسی که در پایین قرار می گیرد)، دارای نام image2.png باشد و هر دوی آنها را در همان فولدر حاوی صفحه PHP قرار داده باشیم، کدهای PHP زیر را می نویسیم :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<?php $top_file = 'image1.png'; $bottom_file = 'image2.png'; $top = imagecreatefrompng($top_file); $bottom = imagecreatefrompng($bottom_file); // show images echo "<img src=\"".$top_file."\">"; echo "<br /><br />"; echo "<img src=\"".$bottom_file."\">"; // get current width/height list($top_width, $top_height) = getimagesize($top_file); list($bottom_width, $bottom_height) = getimagesize($bottom_file); // compute new width/height $new_width = ($top_width > $bottom_width) ? $top_width : $bottom_width; $new_height = $top_height + $bottom_height; // create new image and merge $new = imagecreatetruecolor($new_width, $new_height); imagecopy($new, $top, 0, 0, 0, 0, $top_width, $top_height); imagecopy($new, $bottom, 0, $top_height+1, 0, 0, $bottom_width, $bottom_height); // save to file $new_name='merged_image.png'; imagepng($new, $new_name); // show image echo "<br /><br />"; echo "<img src=\"".$new_name."\">"; // free the memory imagedestroy($top); imagedestroy($bottom); imagedestroy($new); ?> |
بعد از اجرای کدها، یک عکس با نام merged_image.png درون همان فولدر حاوی فایل PHP شامل کدها، ساخته می شود.
چون عکس اول دارای عرض کمتری بوده است، بنابراین در کنار آن، به جای قسمتی که خالی می ماند، رنگ سیاه نمایش داده شده است.
برای باز کردن عکس های با پسوند png و ذخیره اطلاعات آنها در حافظه، تابع imagecreatefrompng به کار می رود :
1 2 |
$top = imagecreatefrompng($top_file); $bottom = imagecreatefrompng($bottom_file); |
ابتدا با تابع imagecreatetruecolor ، یک عکس (image source) ساخته ایم (استفاده از این تابع، باعث می شود که رنگ های دو عکس، حفظ شوند و تغییری در رنگ ها، هنگام ساخت عکس نهایی، نداشته باشیم). سپس با تابع imagecopy ، دو عکس دیگر را در آن قرار داده ایم :
1 2 3 |
$new = imagecreatetruecolor($new_width, $new_height); imagecopy($new, $top, 0, 0, 0, 0, $top_width, $top_height); imagecopy($new, $bottom, 0, $top_height+1, 0, 0, $bottom_width, $bottom_height); |
تابع imagepng برای ساخت یا ذخیره (save) یک عکس با فرمت PNG به کار می رود :
1 |
imagepng($new, $new_name); |
تابع imagedestroy برای آزاد کردن حافظه اشغال شده توسط اطلاعات عکس، به کار می رود (اطلاعات عکس را از حافظه پاک می کند) :
1 2 3 |
imagedestroy($top); imagedestroy($bottom); imagedestroy($new); |