<?php $file = "example.jpg"; $type = getimagesize( $file ); //取得图片的大小,类型等 $file_content = base64_encode( file_get_contents( $file ) ); switch ( $type[2] ) { //判读图片类型 case 1: $img_type = "gif"; break; case 2: $img_type = "jpg"; break; case 3: $img_type = "png"; break; } $img = ‘data:image/‘ . $img_type . ‘;base64,‘ . $file_content; //合成图片的base64编码 echo ‘<img src="‘ . $img . ‘" >‘; ?>
时间: 2024-10-13 19:24:56