簡體   English   中英

嘗試調整大小並裁剪縮略圖圖像

[英]Trying to resize and crop image for thumbnail

我想做的是調整大小並裁剪上傳圖像的中心。 到目前為止,我已經掌握了調整圖像大小的地方,僅此而已。 我知道影像復制功能就是我想要的,但是我很難讓它與我的功能一起使用。

到目前為止,這就是我所擁有的。

/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);

/* find the "desired height" of this thumbnail, relative to the desired width  */
$desired_height = floor($height*($desired_width/$width));

/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width,$desired_height);

/* copy source image at a resized size */

imagecopyresampled($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);

/* create the physical thumbnail image to its destination */
imagejpeg($virtual_image,$dest);

我只需要知道在哪里以及如何合並圖像復制功能。

謝謝。

看一下這堂課 像您提供的示例一樣,它合並了GD2,還具有其他用於縮略圖生成的調整大小算法。

這是我使用imagemagick / php編寫的一個函數,用於執行此操作:

stackoverflow.com/questions/20927238

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM