我不想在我的Bundle中使用tempFiles,所以我只在我的函数中获取给定图片的内容/正文:
$pictureHandler = $this->get('picture.handler');
$body = file_get_contents("water.jpg", "r+");
$thumbnails = $pictureHandler->generateThumbnail($body);
在我的generateThumbnail()函数中,我将给定的“body”保存在PictureEntity中。
现在可以获取这个身体的信息,例如:宽度,高度,大小......? 因为通常使用完整的URL来获取这些信息。像
$info = getimagesize($url);
感谢!!!
答案 0 :(得分:2)
两种可能性:
(我已经做了一篇文章,解释为什么当你想要在实体here中调整图像大小时使用大锤来破解与Symfony的坚果时的感觉 - 它是法语的)< / p>
private function resizeImage($filename, $max_width, $max_height)
{
list($orig_width, $orig_height) = getimagesize($filename);
$width = $orig_width;
$height = $orig_height;
# taller
if ($height > $max_height) {
$width = ($max_height / $height) * $width;
$height = $max_height;
}
# wider
if ($width > $max_width) {
$height = ($max_width / $width) * $height;
$width = $max_width;
}
$height = intval($height);
$width = intval($width);
$image_p = imagecreatetruecolor($width, $height);
switch (exif_imagetype($filename)) {
case 1: /* IMAGETYPE_GIF */
$image = imagecreatefromgif($filename);
break;
case 2: /* IMAGETYPE_JPEG */
$image = imagecreatefromjpeg($filename);
break;
case 3: /* IMAGETYPE_PNG */
$image = imagecreatefrompng($filename);
break;
case 4: /* IMAGETYPE_SWF */
case 5: /* IMAGETYPE_PSD */
case 6: /* IMAGETYPE_BMP */
case 7: /* IMAGETYPE_TIFF_II (ordre d'octets d'Intel) */
case 8: /* IMAGETYPE_TIFF_MM (ordre d'octets Motorola) */
case 9: /* IMAGETYPE_JPC */
case 10: /* IMAGETYPE_JP2 */
case 11: /* IMAGETYPE_JPX */
case 12: /* IMAGETYPE_JB2 */
case 13: /* IMAGETYPE_SWC */
case 14: /* IMAGETYPE_IFF */
case 15: /* IMAGETYPE_WBMP */
case 16: /* IMAGETYPE_XBM */
case 17: /* IMAGETYPE_ICO */
throw new Exception("This kind of images is not handled");
}
imagecopyresampled(
$image_p, $image, 0, 0, 0, 0, $width, $height,
$orig_width, $orig_height
);
return $image_p;
}