Search Results

Search found 6055 results on 243 pages for 'forms'.

Page 148/243 | < Previous Page | 144 145 146 147 148 149 150 151 152 153 154 155  | Next Page >

  • getting Cannot identify image file when trying to create thumbnail in django

    - by Mo J. Mughrabi
    Am trying to create a thumbnail in django, am trying to build a custom class specifically to be used for generating thumbnails. As following from StringIO import StringIO from PIL import Image class Thumbnail(object): source = '' size = (50, 50) output = '' def __init__(self): pass @staticmethod def load(src): self = Thumbnail() self.source = src return self def generate(self, size=(50, 50)): if not isinstance(size, tuple): raise Exception('Thumbnail class: The size parameter must be an instance of a tuple.') self.size = size # resize properties box = self.size factor = 1 fit = True image = Image.open(self.source) # Convert to RGB if necessary if image.mode not in ('L', 'RGB'): image = image.convert('RGB') while image.size[0]/factor > 2*box[0] and image.size[1]*2/factor > 2*box[1]: factor *=2 if factor > 1: image.thumbnail((image.size[0]/factor, image.size[1]/factor), Image.NEAREST) #calculate the cropping box and get the cropped part if fit: x1 = y1 = 0 x2, y2 = image.size wRatio = 1.0 * x2/box[0] hRatio = 1.0 * y2/box[1] if hRatio > wRatio: y1 = int(y2/2-box[1]*wRatio/2) y2 = int(y2/2+box[1]*wRatio/2) else: x1 = int(x2/2-box[0]*hRatio/2) x2 = int(x2/2+box[0]*hRatio/2) image = image.crop((x1,y1,x2,y2)) #Resize the image with best quality algorithm ANTI-ALIAS image.thumbnail(box, Image.ANTIALIAS) # save image to memory temp_handle = StringIO() image.save(temp_handle, 'png') temp_handle.seek(0) self.output = temp_handle return self def get_output(self): return self.output.read() the purpose of the class is so i can use it inside different locations to generate thumbnails on the fly. The class works perfectly, I've tested it directly under a view.. I've implemented the thumbnail class inside the save method of the forms to resize the original images on saving. in my design, I have two fields for thumbnails. I was able to generate one thumbnail, if I try to generate two it crashes and I've been stuck for hours not sure whats the problem. Here is my model class Image(models.Model): article = models.ForeignKey(Article) title = models.CharField(max_length=100, null=True, blank=True) src = models.ImageField(upload_to='publication/image/') r128 = models.ImageField(upload_to='publication/image/128/', blank=True, null=True) r200 = models.ImageField(upload_to='publication/image/200/', blank=True, null=True) uploaded_at = models.DateTimeField(auto_now=True) Here is my forms class ImageForm(models.ModelForm): """ """ class Meta: model = Image fields = ('src',) def save(self, commit=True): instance = super(ImageForm, self).save(commit=True) file = Thumbnail.load(instance.src) instance.r128 = SimpleUploadedFile( instance.src.name, file.generate((128, 128)).get_output(), content_type='image/png' ) instance.r200 = SimpleUploadedFile( instance.src.name, file.generate((200, 200)).get_output(), content_type='image/png' ) if commit: instance.save() return instance the strange part is, when i remove the line which contains instance.r200 in the form save. It works fine, and it does the thumbnail and stores it successfully. Once I add the second thumbnail it fails.. Any ideas what am doing wrong here? Thanks Update: I tried earlier doing the following but I still got the same error class ImageForm(models.ModelForm): """ """ class Meta: model = Image fields = ('src',) def save(self, commit=True): instance = super(ImageForm, self).save(commit=True) instance.r128 = SimpleUploadedFile( instance.src.name, Thumbnail.load(instance.src).generate((128, 128)).get_output(), content_type='image/png' ) instance.r200 = SimpleUploadedFile( instance.src.name, Thumbnail.load(instance.src).generate((200, 200)).get_output(), content_type='image/png' ) if commit: instance.save() return instance

    Read the article

  • Saving multiple select form data in db

    - by fl00r
    Hi. I've got form for some model A, which has got few fields: tile description ... colors colors are selected from multiple select and options are ['red', 'green', 'blue', 'yellow']. User can choose colors as many as he wants. I don't think that making Color model and has_many relationship is good solution here to store colors data in model A. So question is: How to store multiple data in db for such multiple select forms?

    Read the article

  • Custom Visual Studio 2008 Designer

    - by Mick
    How do I create a custom Visual Studio 2008 UI designer for a C# file? For example, when you double click on a DataSet in the Solution Explorer, a UI screen appears that allows you to edit the DataSet, even though it is defined in XML/code (which you can right click and "View Code"). Usually this code is separated from user code in some way, either by region ("Windows Forms Designer Generated Code"), by codegen (".g.cs" for WPF XAML files), or some other means like partial classes.

    Read the article

  • asp.net dropdown list postback to anchor

    - by The Talking Walnut
    How can I go to an anchor tag on the page when the myDropDownList_SelectedIndexChanged() event fires? I am using regular ASP.NET Forms. Update: The following is valid for an ASP.NET Button. I would like to achieve the same functionality (going to #someAnchor) when I select an option from the Dropdown list. <asp:Button ID="btnSubmit" runat="server" Text="Do IT" Width="186px" PostBackUrl="#myAnchor" CausesValidation="false" />

    Read the article

  • Bad Request (400): Why?

    - by ProfK
    Why do I get a 400 - bad request error using the following URL? It is encoded using Server.UrlEncode. The actual path query parameter is C:\Development\Chase\Exports\ChaseExport-090312073930.zip http://localhost:50199/Common/Forms/Export_Stream.aspx%3fpath%3dC%3a%5CDevelopment%5CChase%5CExports%5CChaseExport-090312073930.zip

    Read the article

  • Good Way to Debug Visual Studio Designer Errors

    - by Daisuke Shimamoto
    Hi, Does anyone know a good way to debug errors in the Visual Studio Designer? In our project we have tons of UserControls and many complex forms. For the complex ones, the Designer often throws various exceptions which doesn't help much and was wondering if there's some nice way to figure out what has gone wrong. The language is C# and we're using Visual Studio 2005. Thanks, Daisuke

    Read the article

  • Get methods params type parsing wsdl file in a rails/ruby application

    - by Marco Sangiorgi
    Hi, I have a question about ruby and wsdl soap. I couldn't find a way to get each method's params and their type. For example, if I found out that a soap has a methods called "get_user_information" (using wsdlDriver) is there a way to know if this method requires some params and what type of params does it require (int, string, complex type, ecc..)? I'd like to be able to build html forms from a remote wsdl for each method... Sorry for my horrible English :D

    Read the article

  • Foreign Keys Duplicated in DataGridView

    - by John Doe
    I created a Windows Forms Application to which I added a DataGridView and LINQ to SQL Classes from one of my databases. I can successfully bind one of my database's tables to my DataGridView: var dataSource = from c in _db.NetworkedEquipments select c; dataGridView1.DataSource = dataSource; However, the foreign keys get duplicated, that is, the columns appear twice. How can I prevent this?

    Read the article

  • textbox accept only digits

    - by hiba salem
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Dim allowedChars As String = "0123456789$," If allowedChars.IndexOf(e.KeyChar) = -1 Then ' Invalid Character e.Handled = True End If End Sub this code accept only digits and its working like a charm but if i typed a wrong number its not allowing me to use the delete or the backspace on the keyboard how to solve this problem ?

    Read the article

  • Form allow click-through in C#

    - by Tommy
    Hey, so I have a form, and i've set it to semi-transparent. i'd like for people to be able to click on the forms area, and the form not handle the click, but instead whatever is underneath it handle the click. is this possible?

    Read the article

  • How to get RSS feed item count?

    - by Adam Kane
    Hello, In C#, .NET 3.5, in a Windows Forms application... How does one get the integer count of the number of items that a given RSS url returns? Example: For my blog at: http://forgefx.blogspot.com/feeds/posts/default The expected result would be: postCount = 25 Thanks!

    Read the article

  • SQLAlchemy introspection

    - by Shaman
    What I am trying to do is to get from SqlAlchemy entity definition all it's Column()'s, determine their types and constraints, to be able to pre-validate, convert data and display custom forms to user. How can I introspect it? Example: class Person(Base): ''' Represents Person ''' __tablename__ = 'person' # Columns id = Column(String(8), primary_key=True, default=uid_gen) title = Column(String(512), nullable=False) birth_date = Column(DateTime, nullable=False) I want to get this id, title, birth date, determine their restrictions (such as title is string and max length is 512 or birth_date is datetime etc) Thank you

    Read the article

  • Is it possible to make ListView display a text obtained through its ListViewItem.Tag?

    - by Dimitri C.
    I'd like to fill System.Windows.Forms.ListView with the items I've stored in a separate System.Collections.Generics.List<. I would like to avoid to store the data twice, once in the List< and once as a string in ListViewItem. Is there a way to make ListViewItem use some callback function to obtain the text to put in its columns from the Tag property, instead of using its Text property?

    Read the article

  • What´s the easiest way for a user authentication in SharePoint 2010

    - by user312084
    Hi, does anybody have a manuel that describes the steps to create an anonymous user authentication in SharePoint 2010 (Website for the internet with no authentication). For editing an admin has to log in with forms authentication. Can I hold the admin somewhere in the web.config with membership provider ? Or do I need to install SQL Server somewhere for that task ? Thanx a lot. Stephan

    Read the article

  • How is the default constructor of System.Drawing.Graphics removed?

    - by Albert Iordache
    When I try to create an object of Graphics, why doesn't the following work? System.Drawing.Graphics graphicsObj = new System.Drawing.Graphics(); (I am aware that I could create a private System.Windows.Forms.Panel Obj; and then do CreateGraphics() if I wanted it to work) I tried to find a custom constructor for Graphics, but I couldn't find one. Where did Microsoft define it, or how did it block it?

    Read the article

  • Custom Programing on a SharePoint Server site

    - by hminaya
    Which route should I take? A) Using a SharePoint 2010 Visual Studio Project B) Building a normal asp.net website and incluing my pages using the "Web Part Page" web part in SharePoint Basically I'll be doing some workflows, like filling out travel expenses forms, with approval and feedback.

    Read the article

< Previous Page | 144 145 146 147 148 149 150 151 152 153 154 155  | Next Page >