Search Results

Search found 66 results on 3 pages for 'imagefield'.

Page 1/3 | 1 2 3  | Next Page >

  • Django ImageField issue with JPEG's

    - by Kieran Lynn
    I am having a major issue with PIL (Python Image Library) in Django and have jumpped through a lot of hoops and have thus far not been able to figure out what the root of the issue is. The problem essentially breaks down to not being able to upload JPEG images through the ImageField in the Django admin. But the issue is not as simple as installing libjpeg. First, I installed PIL (through Buildout) and realized once it was installed that I had not installed libjpeg because JPEG support was not available. Having not setup the server myself, I just assumed that it was not installed and I compiled libjpeg 8 from the source. This ended up in my /usr/local/lib/ directory. I cleared out my Buildout files and rebuilt everything. This time when PIL compiled I had JPEG support. But I went to the Django Admin and tried to upload a JPEG though an ImageField with no luck. I got the "Upload a valid image. The file you uploaded was either not an image or a corrupted image" error. Just as a test I opened up a the Djano shell and ran the following: > import Image > i = Image.open( "/absolute_path/file.jpg" ) > print i <JpegImagePlugin.JpegImageFile image mode=RGB size=940x375 at 0x7F908C529BD8> This runs with no errors and shows that PIL is able to open JPEG's. After doing some reading, I come across this thread: Is it possible to control which libraries apache uses? Looks like PHP also uses libjpeg and is loading before Django, and therefor loading libjpeg 6.2 before. This is show when using lsof: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME apache2 2561 www-data mem REG 202,1 146032 639276 /usr/lib/libjpeg.so.62.0.0 So my thought is that I should be using libjpeg 6.2. So I removed libjpeg located in my /usr/local/lib directory. After rereading the PIL installation instructions, I realized that I might not have the dev/header files for libjpeg that PIL needs. So I also uninstalled libjpeg using the aptitude uninstaller (sudo aptitude remove libjpeg62). Then to ensure that I got the header files that PIL needed I installed libjpeg using aptitude: (sudo aptget install libjpeg62-dev). From here I cleaned out my Buildout directory, and reran Buildout, which in turn reinstalled PIL. Once again, I have JPEG support, now using the libjpeg62. So I go to test in the Django Admin. Still no JPEG support. So I wanted to test JPEG support in general and see if the exception was not handled, what kind of error it would throw. So in my homepage view I added the following code to open a JPEG image: import Image i = Image.open( "/absolute_path/file.jpg" ) v = i.verify() Then I pass i to the HTML view just to easily see the output. I deploy these changes to the server and restart. I am surprised not to see an error and get the following output: {{ i }} - <JpegImagePlugin.JpegImageFile image mode=RGB size=940x375 at 0x7F908C529BD8> {{ v }} - None So at this point I am really confused: Why can I successfully open a JPEG while the admin cannot? Am I missing something, is this not an issue with libjpeg? If not an issue with libjpeg, why can I upload a PNG with no issues? Any help would be much appreciated, I have been on this for 2 days debugging with no luck. Setup: 1. Rackspace Cloud Server 2. Ubuntu 10.04 3. Django 1.2.3 (Installed though Buildout) 4. PIL 1.1.7 (Installed though Buildout) 5. libjpeg 6.2 (installed through aptitude (sudo aptget install libjpeg62-dev)

    Read the article

  • asp:GridView ImageField DataImageUrlField - specifying multiple fields?

    - by Jason Jong
    I know I can use asp:TemplateField for this, but using the standard asp:BoundField or asp:ImageField in the asp:GridView, is it possible to specify multiple fields and use them in the FormatString field as {0} {1} {2} etc... For example <asp:ImageField DataImageUrlField="ProfileImageId,UserGuid" DataImageUrlFormatString="img-profile.ashx?uid={0}&pid={1}" /> I've always pondered on this. This would be much neater than using asp:TemplateField

    Read the article

  • Django and ImageField Question

    - by Hellnar
    Hello I have a such model: Foo (models.Model): slug = models.SlugField(unique=True) image = models.ImageField(upload_to='uploads/') I want to do two things with this: First of all, I want my image to be forced to resize to a specific width and height after the upload. I have tried this reading the documentation but seems to getting error: image = models.ImageField(upload_to='uploads/', height_field=258, width_field=425) Secondly, when adding an item via admin panel, I want my image's file name to be renamed as same as slug, if any issue arises (like if such named image already exists, add "_" to the end as it used to do. IE: My slug is i-love-you-guys , uploaded image such have i-love-you-guys.png at the end.

    Read the article

  • Django ImageField validation & PIL

    - by Zayatzz
    Hello On sunday, I had problems with python modules, when I installed stackless python. Now I have compiled and installed : setuptools & python-mysqldb and i got my django project up and running again. (i also reinstalled django-1.1), Then I compiled and installed, jpeg, freetype2 and PIL. I also started using mod_wsgi instead of mod_python. But when uploading imagefield in form I get validationerror: Upload a valid image. The file you uploaded was either not an image or a corrupted image. Searchmonkey shows that it comes from field.py imagefield validation. before raising this error it imports Image from PIL, opens file and verfies it. I tried importing PIL from python prompt manually - it worked just fine. Same with Image.open and Image.verify. So what could be causing this problem? Alan

    Read the article

  • Drupal: Programmatically saving imagefield images

    - by Ace
    Hey there! I'm trying to write a sync function that saves some data to nodes, which works fine, until I try to save the thumbnail image associated with the node. I've managed to download the file and put it in my sites/default/files folder, but what's the best way to tell Drupal, "put this file in that CCK imagefield"? EDIT To clarify a bit.. I sync the thumbnails separately (since one image can be used by several nodes)... I would like the initial thumbnail sync to save the files in the correct folder (not a temp one) and just point the imagefield to this file... That's what annoys me with field_file_save_file(), it saves a new file instead of just making a pointer.. Any advice?

    Read the article

  • Django - how to make ImageField/FileField optional?

    - by ilya
    class Product(models.Model): ... image = models.ImageField(upload_to = generate_filename, blank = True) When I use ImageField (blank=True) and do not select image into admin form, exception occures. In django code you can see this: class FieldFile(File): .... def _require_file(self): if not self: raise ValueError("The '%s' attribute has no file associated with it." % self.field.name) def _get_file(self): self._require_file() ... Django trac has ticket #13327 about this problem, but seems it can't be fixed soon. How to make these field optional?

    Read the article

  • Drupal: how to display CCK ImageField descriptions

    - by Patrick
    hi, I'm using CCK ImageField on Drupal and I would like to display the "Description" field below it. I'm considering to use Custom Formatters module to display them. http://drupal.org/project/custom_formatters Can you give me some feedback ? Is this a good solution to my problem ? thanks

    Read the article

  • mix together cck imageField and videoField in one ordered list

    - by Patrick
    hi, I'm using imageField and videoField into each node of my website and I'm using multiple files option, so that I have 2 ordered lists. This works great, however I would like to have only 1 ordered list instead of 2, so that my customer can arrange video and images in the same list and ordered them i.e. video1 image1 video2 video3 image2 ... etc thanks

    Read the article

  • Django gives "I/O operation on closed file" error when reading from a saved ImageField

    - by Rob Osborne
    I have a model with two image fields, a source image and a thumbnail. When I update the new source image, save it and then try to read the source image to crop/scale it to a thumbnail I get an "I/O operation on closed file" error from PIL. If I update the source image, don't save the source image, and then try to read the source image to crop/scale, I get an "attempting to read from closed file" error from PIL. In both cases the source image is actually saved and available in later request/response loops. If I don't crop/scale in a single request/response loop but instead upload on one page and then crop/scale in another page this all works fine. This seems to be a cached buffer being reused some how, either by PIL or by the Django file storage. Any ideas on how to make an ImageField readable after saving?

    Read the article

  • Drupal Imagecache Actions with ImageField and Node variables

    - by HS2323
    I am able to add text to onto a imagefield using the imagecache textrender preset action (for a content type). I pull the node title using the following in the imagecache preset text: global $node; return $node->title; However this only works when an image is uploaded when creating new content. If I have an image set as a default for the content type (and none are added when creating the new page) then it won't overlay the node title. I tried just regular text in the preset action field on the default image and it worked. Can anyone help me with this?

    Read the article

  • Django ModelForm Imagefield Upload

    - by Wei Xu
    I am pretty new to Django and I met a problem in handling image upload using ModelForm. My model is as following: class Project(models.Model): name = models.CharField(max_length=100) description = models.CharField(max_length=2000) startDate = models.DateField(auto_now_add=True) photo = models.ImageField(upload_to="projectimg/", null=True, blank=True) And the modelform is as following: class AddProjectForm(ModelForm): class Meta: model = Project widgets = { 'description': Textarea(attrs={'cols': 80, 'rows': 50}), } fields = ['name', 'description', 'photo'] And the View function is: def addProject(request, template_name): if request.method == 'POST': addprojectform = AddProjectForm(request.POST,request.FILES) print addprojectform if addprojectform.is_valid(): newproject = addprojectform.save(commit=False) print newproject print request.FILES newproject.photo = request.FILES['photo'] newproject.save() print newproject.photo else: addprojectform = AddProjectForm() newProposalNum = projectProposal.objects.filter(solved=False).count() return render(request, template_name, {'addprojectform':addprojectform, 'newProposalNum':newProposalNum}) the template is: <form class="bs-example form-horizontal" method="post" action="">{% csrf_token %} <h2>Project Name</h2><br> {{ addprojectform.name }}<br> <h2>Project Description</h2> {{ addprojectform.description }}<br> <h2>Image Upload</h2><br> {{ addprojectform.photo }}<br> <input type="submit" class="btn btn-success" value="Add Project"> </form> Can anyone help me or could you give an example of image uploading? Thank you!

    Read the article

  • Django, want to upload eather image (ImageField) or file (FileField)

    - by Serg
    I have a form in my html page, that prompts user to upload File or Image to the server. I want to be able to upload ether file or image. Let's say if user choose file, image should be null, and vice verso. Right now I can only upload both of them, without error. But If I choose to upload only one of them (let's say I choose image) I will get an error: "Key 'attachment' not found in <MultiValueDict: {u'image': [<InMemoryUploadedFile: police.jpg (image/jpeg)>]}>" models.py: #Description of the file class FileDescription(models.Model): TYPE_CHOICES = ( ('homework', 'Homework'), ('class', 'Class Papers'), ('random', 'Random Papers') ) subject = models.ForeignKey('Subjects', null=True, blank=True) subject_name = models.CharField(max_length=100, unique=False) category = models.CharField(max_length=100, unique=False, blank=True, null=True) file_type = models.CharField(max_length=100, choices=TYPE_CHOICES, unique=False) file_uploaded_by = models.CharField(max_length=100, unique=False) file_name = models.CharField(max_length=100, unique=False) file_description = models.TextField(unique=False, blank=True, null=True) file_creation_time = models.DateTimeField(editable=False) file_modified_time = models.DateTimeField() attachment = models.FileField(upload_to='files', blank=True, null=True, max_length=255) image = models.ImageField(upload_to='files', blank=True, null=True, max_length=255) def __unicode__(self): return u'%s' % (self.file_name) def get_fields(self): return [(field, field.value_to_string(self)) for field in FileDescription._meta.fields] def filename(self): return os.path.basename(self.image.name) def category_update(self): category = self.file_name return category def save(self, *args, **kwargs): if self.category is None: self.category = FileDescription.category_update(self) for field in self._meta.fields: if field.name == 'image' or field.name == 'attachment': field.upload_to = 'files/%s/%s/' % (self.file_uploaded_by, self.file_type) if not self.id: self.file_creation_time = datetime.now() self.file_modified_time = datetime.now() super(FileDescription, self).save(*args, **kwargs) forms.py class ContentForm(forms.ModelForm): file_name =forms.CharField(max_length=255, widget=forms.TextInput(attrs={'size':20})) file_description = forms.CharField(widget=forms.Textarea(attrs={'rows':4, 'cols':25})) class Meta: model = FileDescription exclude = ('subject', 'subject_name', 'file_uploaded_by', 'file_creation_time', 'file_modified_time', 'vote') def clean_file_name(self): name = self.cleaned_data['file_name'] # check the length of the file name if len(name) < 2: raise forms.ValidationError('File name is too short') # check if file with same name is already exists if FileDescription.objects.filter(file_name = name).exists(): raise forms.ValidationError('File with this name already exists') else: return name views.py if request.method == "POST": if "upload-b" in request.POST: form = ContentForm(request.POST, request.FILES, instance=subject_id) if form.is_valid(): # need to add some clean functions # handle_uploaded_file(request.FILES['attachment'], # request.user.username, # request.POST['file_type']) form.save() up_f = FileDescription.objects.get_or_create( subject=subject_id, subject_name=subject_name, category = request.POST['category'], file_type=request.POST['file_type'], file_uploaded_by = username, file_name=form.cleaned_data['file_name'], file_description=request.POST['file_description'], image = request.FILES['image'], attachment = request.FILES['attachment'], ) return HttpResponseRedirect(".")

    Read the article

  • How to access image folder in django

    - by anc1revv
    I just started django and i want to access images uploaded by a user. here is my model: class Food(models.Model): name = models.CharField(max_length=100) price = models.DecimalField(max_digits=4, decimal_places=2) quantity = models.IntegerField(blank=True, null=True) description = models.CharField(max_length=200) location = models.CharField(max_length=100) time = models.DateTimeField() photo_thumbnail = models.ImageField(upload_to="images") photo_fullsize = models.ImageField(upload_to="images") i stored the image in the "images" folder below the html is this: img src="{{steak.photo_thumbnail}}" and steak.photo_thumbnail = images/steak_and_egg_thumbnail_1.png here is the error i get: [06/Jul/2012 19:08:24] "GET /menu/ HTTP/1.1" 200 99 [06/Jul/2012 19:08:24] "GET /menu/images/steak_and_egg_thumbnail_1.png HTTP/1.1" 404 2127

    Read the article

  • Drupal: CCK ImageField, multi-line description

    - by Patrick
    hi, I'm using CCK Image field (multi-images) and for each image I have the "Description" field, where I can add the image description. I was wondering if I can have multi-line description, instead of only one line. (Even using some specific symbol to go next line) thanks

    Read the article

  • Using hyperlink control with imagefield control in gridview

    - by niks
    I have a gridview and a column of that gridview is displaying images whose path is stored in a database & image is stored in locale folder inside my website. My problem is that I want to use the hyperlink control with the image, so that when the image is clicked it should jump to another page. How can I do that?

    Read the article

  • Django resizing an image pre save using PIL

    - by Ed
    Ugh, I hate having to ask a question on such a common feature, but. . . I'm using an ImageField in a form to upload a photo to S3. I want to resize the image before it is uploaded to S3. I'm trying to use PIL to test the dimensions and resize if necessary. The Image.open() part is throwing me though. It wants a filepath, and the ImageField from the form is only returning the actual file and filename. How can I resize the image before it's saved to S3? Before we get to this point, I'm not using sorl because I believe sorl is compatible with models using ImageFields. But the model associated with the saved S3 images holds just the url of the image on S3 as opposed to using ImageFields.

    Read the article

  • Why does sorl.thumbnail ImageField fail in the admin?

    - by Mark0978
    I have code that looks like this: from sorl.thumbnail import ImageField class Gallery(models.Model): pass class GalleryImage(models.Model): image = ImageField(upload_to='galleries') In the admin: class GalleryImageInline(admin.TabularInline): model = GalleryImage class GalleryAdmin(admin.ModelAdmin): inlines = (GalleryImageInline,) If I use the sorl.thumbnail as above, it is impossible to add images in the admin. I get the validation error Enter a list of values. If I replace the sorl.thumbnail.ImageField with a plain django ImageField, everything works. If I want sorl.thumbnail to clean up the cache thumbnails, I need to use it in the model, but if I use it in the model, I can't seem to add any images to need thumbnails. Anyone else found and fixed this problem yet?

    Read the article

  • django admin: Add a "remove file" field for Image- or FileFields

    - by w-
    I was hunting around the net for a way to easily allow users to blank out imagefield/filefields they have set in the admin. I found this http://www.djangosnippets.org/snippets/894/ What was really interesting to me here was the code posted in the comment by rfugger remove_the_file = forms.BooleanField(required=False) def save(self, *args, **kwargs): object = super(self.__class__, self).save(*args, **kwargs) if self.cleaned_data.get('remove_the_file'): object.the_file = '' return object When i try to use this in my own form I basically added this to my admin.py which already had a BlahAdmin class BlahModelForm(forms.ModelForm): class Meta: model = Blah remove_img01 = forms.BooleanField(required=False) def save(self, *args, **kwargs): object = super(self.__class__, self).save(*args, **kwargs) if self.cleaned_data.get('remove_img01'): object.img01 = '' return object when i run it I get this error maximum recursion depth exceeded while calling a Python object at this line object = super(self.__class__, self).save(*args, **kwargs) When i think about it for a bit, it seems obvious that it is just infinitely calling itself causing the error. My problem is i can't figure out what is the correct way i should be doing this. Any suggestions? thanks

    Read the article

  • Upload Image with Django Model Form

    - by jmitchel3
    I'm having difficulty uploading the following model with model form. I can upload fine in the admin but that's not all that useful for a project that limits admin access. #Models.py class Profile(models.Model): name = models.CharField(max_length=128) user = models.ForeignKey(User) profile_pic = models.ImageField(upload_to='img/profile/%Y/%m/') #views.py def create_profile(request): try: profile = Profile.objects.get(user=request.user) except: pass form = CreateProfileForm(request.POST or None, instance=profile) if form.is_valid(): new = form.save(commit=False) new.user = request.user new.save() return render_to_response('profile.html', locals(), context_instance=RequestContext(request)) #Profile.html <form enctype="multipart/form-data" method="post">{% csrf_token %} <tr><td>{{ form.as_p }}</td></tr> <tr><td><button type="submit" class="btn">Submit</button></td></tr> </form> Note: All the other data in the form saves perfectly well, the photo does not upload at all. Thank you for your help!

    Read the article

  • Django: Password protect photo url's?

    - by MikeN
    From my Django application I want to serve up secure photos. The photos are not for public consumption, I only want logged in users to have the ability to view them. I don't want to rely on obfuscated file id's (giving a photo a UUID of a long number) and count on that being hidden in my media folder. How would I store a photo securely on disk in my database and only stream it out to an authenticated session?

    Read the article

  • Drupal 7: Rename files on upload (via filefield)

    - by Eugene
    Looking for a way to rename files that are uploaded by users through a filefield. For example, rename user profile photos using uniqid. I found a good solution for D6 here: http://www.wesjones.net/home/2011/03/drupal-6-how-to-change-filename-on-upload but can't find anything for D7. Another option is to use File (Field) Paths, but (1) the module causes warnings on my setup and (2) seems to be a bit of an overkill to install a general module for a very specific purpose.

    Read the article

  • How do I display many images (by imagefield) in all my nodes of a type?

    - by Leon
    The thing is that I have hundreds of nodes each with 4 to 12 images all of them around the same size in an imagefield but I want to order that so it looks at the end in a grid or something like that. I know that panels and views are the answer but I think I've seen all of the tutorials available but nothing. If anyone know where can I find something like I need, I'll be very gratefull.

    Read the article

  • Deleting files associated with model - django

    - by alexBrand
    I have the following code in one of my models class PostImage(models.Model): post = models.ForeignKey(Post, related_name="images") # @@@@ figure out a way to have image folders per user... image = models.ImageField(upload_to='images') image_infowindow = models.ImageField(upload_to='images') image_thumb = models.ImageField(upload_to='images') image_web = models.ImageField(upload_to='images') description = models.CharField(max_length=100) order = models.IntegerField(null=True) IMAGE_SIZES = { 'image_infowindow':(70,70), 'image_thumb':(100,100), 'image_web':(640,480), } def delete(self, *args, **kwargs): # delete files.. self.image.delete(save=False) self.image_thumb.delete(save=False) self.image_web.delete(save=False) self.image_infowindow.delete(save=False) super(PostImage, self).delete(*args, **kwargs) I am trying to delete the files when the delete() method is called on PostImage. However, the files are not being removed. As you can see, I am overriding the delete() method, and deleting each ImageField. For some reason however, the files are not being removed.

    Read the article

1 2 3  | Next Page >