我希望在将SQL Server映像加载到客户端之前将其最小化。
不幸的是我得到的例子没有实现: Resizing and then displaying BLOB element from database
代码:
client.startDeviceTwin(new MyTwinCallback(), null, dataCollector, null);
编辑:我的简单实现:
package main
import (
"fmt"
"log"
"github.com/PuerkitoBio/goquery"
)
func showRanking(username string) {
URL := fmt.Sprintf("https://leetcode.com/%s", username)
doc, err := goquery.NewDocument(URL)
if err != nil {
log.Fatal(err)
}
ranking, _ := doc.Find("div.panel-body").Find("span.ranking").Attr("data-content")
fmt.Printf("%s's ranking is %v", username, ranking)
}
func main() {
showRanking("aQuaYi")
}
但我收到了这些错误:
警告:imagecreatefromstring():数据不是可识别的格式......
警告:imagescale()要求参数1为资源,布尔值在......
中给出警告:imagedestroy()期望参数1为资源,在......
中给出null
答案 0 :(得分:0)
这可能对您有所帮助,但您必须首先从SQL创建实际图像。 如果你可以将图像文件保存为实际文件,那就更好了。它的速度要快得多。
function resize_image($filename, $tmpname, $xmax, $ymax)
{
$ext = explode(".", $filename);
$ext = $ext[count($ext)-1];
if($ext == "jpg" || $ext == "jpeg")
$im = imagecreatefromjpeg($tmpname);
elseif($ext == "png")
$im = imagecreatefrompng($tmpname);
elseif($ext == "gif")
$im = imagecreatefromgif($tmpname);
$x = imagesx($im);
$y = imagesy($im);
if($x <= $xmax && $y <= $ymax)
return $im;
if($x >= $y) {
$newx = $xmax;
$newy = $newx * $y / $x;
}
else {
$newy = $ymax;
$newx = $x / $y * $newy;
}
$im2 = imagecreatetruecolor($newx, $newy);
imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y);
return $im2;
}