缩小尺寸的图像在大图像工作时未显示 [英] reduced size image not shown while big image works

查看:109
本文介绍了缩小尺寸的图像在大图像工作时未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道为什么它不起作用,我和其他教程完全一样。也许我提取图像的方式是问题。我正在使用imagekit和鹅。任何帮助将不胜感激。
这是我的这个问题的完整代码。

  class PostCreateView(CreateView):
model = Post
form_class = PostForm
template_name ='main / add_post.html'

def form_valid(self,form):
self.object = form.save(commit = False)
#任何手动设置到这里
self.object.moderator = self.request.user
self.object.image = extract(self.object.url)

self.object.save()
return HttpResponseRedirect(reverse('post',args = [self.object.slug]))

提取方法

  def extract(url):
g = Goose()
article = g.extract(url = url)
resposne = {'image':article.top_image.src}
return article.top_image.src

我的模型,保存图片(已被提取)

  class Post(models。模型):
image = models.ImageField(upload_to =images,blank = True,null = True)
image_thumbnail = ImageSpecField(source ='image',
processors = [ResizeToFill 70,70)],
format ='PNG',
options = {'quality':60}

对于post.html

 < img src ={{post .image_thumbnail}}alt =/> 
< img src ={{post.image}}alt =/>

第二个img正在工作,而第一个显示小盒子显示破损的图像
我有正确安装枕头,并且

解决方案

根据我在讨论聊天中的讨论,缩略图的图像url是: p>

 < img src =CACHE / IMAGE / http:/imgur.com/lalala/path/to/image.png> ; 

这是错误的。



你需要修复url,也可能将图像文件转到ImageSpecField,以便正确缩略图。


I really have no idea why it won't work, I did exactly same as other tutorials. Maybe the way I'm extracting image is the problem. I'm using imagekit and goose. Any help would be appreciated. Here is my Full Code for this problem .

class PostCreateView(CreateView):    
     model = Post
     form_class = PostForm
     template_name = 'main/add_post.html'

     def form_valid(self, form):
            self.object = form.save(commit=False)
            # any manual settings go here
            self.object.moderator = self.request.user
            self.object.image = extract(self.object.url) 

            self.object.save()
            return HttpResponseRedirect(reverse('post', args=[self.object.slug]))

For extract method

def extract(url):
    g = Goose()
    article = g.extract(url=url)
    resposne = {'image':article.top_image.src}
    return article.top_image.src

my models, where image is saved(has been extracted)

class Post(models.Model):
    image = models.ImageField(upload_to="images",blank=True, null=True)
    image_thumbnail = ImageSpecField(source='image',
        processors=[ResizeToFill(70,70)],
        format='PNG',
        options={'quality':60}
    )

For post.html

<img src="{{ post.image_thumbnail }}" alt="" />            
<img src="{{ post.image}}" alt="" />

second img is working, while the first one shows small box showing broken image I have installed pillow correctly, and

解决方案

according to discussion I had with you in discussion chat, the image url of thumbnail is:

<img src="CACHE/IMAGE/http:/imgur.com/lalala/path/to/image.png">

which is wrong.

you need to fix the url and possibly also hand image file over to ImageSpecField so it can thumbnail correctly..

这篇关于缩小尺寸的图像在大图像工作时未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆