I wanted to show image from another server, but a smaller image maintaining the aspect ratio and i will not be knowing the exact size of that image. Can i do this?
1条回答 默认 最新
dongze5043 2012-03-09 10:16关注First you need to grab the image from another server, for that you can use
file_get_contents().Then you need some code to resize an image. Since you have the image content in a string rather than a local file, you can use
imagecreatefromstring()try here: curl and resize remote imageIf you want to resize it down relative to the original then use
getimagesizefromstring()to get the current size, then simply calculate the new size based on your chosen percentage.$content = file_get_contents('http://site.com/image.jpg'); $originalSize = getimagesizefromstring($content); $originalWidth = $originalSize[0]; $originalheight = $originalSize[1]; $newSize = 0.6; // 60% of the original size $newWidth = $originalWidth * $newSize; $newHeight = $originalHeight * $newSize; // now you know what the resized width and height should be, you can go ahead and do the actual resizing本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报