Jump to content

M.O.S. Studios

Members
  • Posts

    282
  • Joined

  • Last visited

Posts posted by M.O.S. Studios

  1. Figured it out.

     

    Here is my round about way to take a CSV file, and visualize it as a table.

     

    <?php
    
    require('fpdf.php');
    $file  = file.csv';
    
    function near5($v){
        return round($v * 2) / 2;
    }
    
    function content($file){
        $header = array();
        if (($handle = fopen($file, "r")) !== FALSE){
            $body   = array();
            $header = fgetcsv($handle);
            $header[0] = 'Category/Weight(Lbs)';
            while (($data = fgetcsv($handle)) !== FALSE){
                $body[]  = $data;
            }
            fclose($handle);
        }
        return array($header, $body);
    }
    
    class PDF extends FPDF{
        // Simple table
        function BasicTable($header, $data, $kcal){
            // Header
            $first = 30;
            foreach($header as $col){
                $v = is_numeric($col) ? round(($col*2.2),1) : $col;
                $this->Cell($first,7,$v,1,0,'C');
                $first = 10;
            }
            $this->Ln();
            // Data
    
            foreach($data as $row){
                $first = 30;
                foreach($row as $col){
                    $v = (is_numeric($col)) ? near5($col/$kcal) : $col;
                    $this->Cell($first,7,$v,1,0,'C');
                    $first = 10;
                }
                $this->Ln();
            }
        }
    }
    
    
    // Column headings
    content($file);
    list($header, $row) = content($file);
    // Data loading
    $pdf = new PDF();
    $pdf->SetFont('Arial','',5);
    $pdf->AddPage();
    $pdf->BasicTable($header,$row, $kcal);
    
    $output = $pdf->Output('S');
    
    $im = new imagick();
    $im->setResolution(300, 300);
    $im->readImageBlob($output);
    $im->setImageFormat('png');
    $im->setImageCompression(imagick::COMPRESSION_JPEG); 
    $im->setImageCompressionQuality(100);
    
    $im->borderImage("#ffffff", 20, 20);
    $im->trimImage(0.3);
    $im->setImagePage($im->getImageWidth(), $im->getImageHeight(), 0, 0);
    
    header("Content-Type: image/" . $im->getImageFormat());
    echo $im->getImageBlob();
    
    $im->clear();
    $im->destroy();
    ?>

     

  2. So I was working on this for a bit, and I found a round about way to do it.

     

    It requires FPDF, and Imagick.

    <?php
    
    require('fpdf.php');
    $file  = 'file.CSV';
    $kcal = 2000 / 1000;
    
    function near5($v){
        return round($v * 2) / 2;
    }
    
    function content($file){
        $header = array();
        if (($handle = fopen($file, "r")) !== FALSE){
            $body   = array();
            $header = fgetcsv($handle);
            $header[0] = 'Category/Weight(Lbs)';
            $w = 20 + (count($header)*10);
            $h = 7;
            while (($data = fgetcsv($handle)) !== FALSE){
                $body[]  = $data;
                $h += 7;
            }
            fclose($handle);
        }
        return array($header, $body, $h, $w);
    }
    
    class PDF extends FPDF{
        // Simple table
        function BasicTable($header, $data, $kcal){
            // Header
            $first = 30;
            foreach($header as $col){
                $v = is_numeric($col) ? round(($col*2.2),1) : $col;
                $this->Cell($first,7,$v,1,0,'C');
                $first = 10;
            }
            $this->Ln();
            // Data
    
            foreach($data as $row){
                $first = 30;
                foreach($row as $col){
                    $v = is_numeric($col) ? near5($col/$kcal) : $col;
                    $this->Cell($first,7,$v,1,0,'C');
                    $first = 10;
                }
                $this->Ln();
            }
        }
    }
    
    
    // Column headings
    content($file);
    list($header, $row, $h, $w) = content($file);
    // Data loading
    $pdf = new PDF();
    $pdf->SetFont('Arial','',5);
    $pdf->AddPage();
    $pdf->BasicTable($header,$row, $kcal);
    
    $output = $pdf->Output('f.pdf','F');
    $imagick = new Imagick();
    $imagick->readImage('f.pdf');
    $imagick->setImageCompressionQuality(100);
    $imagick->setResolution($w*500,$h*500);
    $imagick->borderImage("#ffffff", 20, 20);
    $imagick->trimImage(0.3);
    
    $imagick->setImagePage($imagick->getImageWidth(), $imagick->getImageHeight(), 0, 0);
    $imagick->setImageFormat("png");
    
    header("Content-Type: image/" . $imagick->getImageFormat());
    echo $imagick->getImageBlob();
    
    unlink('f.pdf');

    two problems and this would work perfectly.

     

    1. The resolution is awful. I tried messing around with the settings; I couldn't figure it out. Any ideas?

    2. I'd prefer to have it where it doesn't save the PDF file. Is there a way I can send it to imagick without saving the file?

    Here is the CSV File

    heaading,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13,h14
    Row1, 2,3,4,5,6,7,8,9,10,11,12,13,14
    another,12,13,14,15,16,17,18,19,110,111,112,113,114
  3. I haven't had time until now to work on this project. I am going to take a crack at it now.
    these images are going to be accessed by a design program that can grab photos from a url.

    Since there is no browser directly involved, I don't think javascript would work.

     

    Thanks for the link! I will take a look at the library 

  4. 1 minute ago, Danishhafeez said:

    Converting a CSV file directly to a JPG image is not a common task, as CSV files typically contain tabular data, while JPG files are images. However, if you have specific requirements for visualizing the data from the CSV file as an image, you may need to create a custom solution.

     

    • Read the CSV file: Use PHP's built-in functions like fgetcsv() to read the CSV file and extract the data.
    • Process the data: Depending on how you want to visualize the data, you'll need to process it accordingly. For example, if you want to create a chart or graph, you might need to calculate values or organize the data in a certain way.
    • Create the image: Use libraries like GD or Imagick in PHP to create and manipulate images. You'll need to determine how to represent the data visually in the image.
    • Save the image: Once you've created the image, save it as a JPG file using the appropriate functions.

    example related to this task:

    i hope you will understand it.

    At first glance this is what I am looking for.

     

    yeah, I wanted to arrange the data as a chart, like how it would be displayed if it was opened in excel.

     

    I am  going to see if I can work with what you sent me

  5.  

    2 minutes ago, requinix said:

    CSV is text data. JPG is image data. It does not make sense to convert one to the other.

    ...unless you have some kind of specific knowledge about this process. Specific knowledge that nobody else probably has. So if your question is "is there a script out there made by someone to happens to share my specific knowledge" then the answer is no.

    Describe, with details, what it is you want to do.

    Php has lots of libraries and functions to turn text into an image.

     

    I want to take a CSV file, and use the values to create a JPG image

    Here is an example of what I am

    looking for. This requires Java, which I don’t have 

  6. Hey everyone!

     

    I’m convert a CSV file into a Jpg file using php.

     

    so, the script would take the information from the CSV file, and create a visual version that can be viewed on program that displays JPG.

     

    anyone of a script that does that? 
     

    i was thinking of making it from scratch, but thought I might be reinventing the wheel

  7. excellent!

     

    ill try it all again, and look at the files.
     

     

    The html source was of the page sending the request on my end!

     

    I had the response sent to the console.log() function so I can more closely examine it. I was getting source code for the html page I wrote to send it

  8. Hey everyone,

     

    I’m trying to write an api call to the Trexity API. They have some documentation here.

    I’ve used apis before, and it’s never been an issue. However I have been trying to get a curl command to connect and I can not. I have an API token, tried using the ‘Bearer’ authentication and I either get a 500 error, or it sends back a response; but it’s just the html source of the page that is sending it.

     

    normally I’d attach source code, but I rage deleted it a few days ago.

     

    I was hoping someone could maybe take a look at the documentation and let me know if they notice  anything unusual…

     

    only thing I see is it uses openAPI; and I don’t know what that is

    I will be making the code again. If I have the same issue, I’ll post the code here 

     

     

    thanks everyone 

     

  9. 8 hours ago, requinix said:

    You have a table for users, right? Add another table that has the user ID and a unique token. That token gets generated when someone uses the "remember me" option and gets stored in a cookie; it should have an expiration, both in the cookie and the database table, of however long you want it to last.
    When the user visits the site and they're logged out, you can use that cookie to look up the user (as long as the token hasn't expired yet, of course). You should also do some other checks to make sure somebody didn't intercept that cookie and start using it themselves, such as by checking the user agent and/or IP address - though both of those can vary legitimately for a user.

     

    Would this be safe? I believe its possible for one website to read cookies from another. Couln't they copy that cookie to access the site?

  10. Hey everyone,

     

    I am working on a project for fun. This is a LAMP application that is going to run on my intranet server, and hold NO VALUABLE data. I am doing it just to get better at programming, and learn some best practices and techniques.

    at this point, I am working on some things, and I don't know what the best practices are. Can someone help me go down the pest route? 

     

    1. A log-in system and I want to include a "remember me" button. What is the best practice for this? Obviously leaving user data in a cookie is asking for trouble, so I was thinking of leaving a unique id of some sort?

    2. Information in a login SESSION. What information do you put in a log in session? I have seen lots of different techniques on this. I don't really know which is the best. For the moment, I keep an array like this: array('Status'=>True, 'Username'=>'Users name"  ,'email'=>'users Email'). If a hacker can inject session information, this seems like it would be really easy to break, because they only need a user's name and email to gain access. Is there something more I should do?

    3. Config file that holds Mysql Information. I made a file that contains all the values that might change over time. That way I only need to change it in one spot. In this file I have things like the Mysql Database information. Should these files be encrypted? Or can I use a .htaccess file to make sure it isn't accessible to a hacker (as I mentioned before, this isn't a project that's going live, its more of an exercise to help me learn)

     

    Thanks everyone

  11. I’m asking for educational purposes, I think understanding why is as important as how.

     

    so, if I understand correctly, the idea is it strictly prevents comparing hashed password together. So one cracked password doesn’t unlock them all?

  12. 17 minutes ago, mac_gyver said:

    the point of hashing passwords is to protect the user's data. it has nothing to do with preventing any type of external attack.

    Maybe I am using the wrong terminology.

     

    if someone got a hold of the DB, the can see the $2y$10$ And assume that’s how it was encrypted. Then run a list of common passwords through password_validate along with the hash.

     

    if it tests each hash against the most common passwords, words, etc..  first, then worked its way down to the least common, it could in theory works out the majority of information.

  13. Hey everyone,

     

    I’m working on an app for my local intranet sever. My security needs are almost non existent, because it’s only accessible on my local network. Even if someone wanted to mess with it, the only thing this app controls is my fish tank! Yup, it just shows me some information about my water, and let’s me turn on and off devices. So I’m not too worried about it.

    That being said, I want to add a password just to keep my coding skills sharp, as I haven’t done anything with php in a while. That being said, I would like some help understanding something...

    while looking up the best practices for working with passwords, I found password_hash and password_verify...

     

    don’t these two function completely negate the advantages of salting a password?

    my understanding is that salting a password makes using a rainbow table impossible. However, what’s stopping someone from just doing a dictionary attack with the password_verify function?

    as I said above, my application doesn’t require a lot of security, I’m asking for educational reasons

  14. Hey everyone,

    I’m pretty new to python, but have done a lot of coding with php and JavaScript.

     

    here is what I am hoping to do.

    i want to write a script that will do the following:

    1. scan sub directory make an array with the names of each of the files

    2. iterate through the files using the array, and make either a object, or a function using the file name (without the extension) as the name, and the contents for the code

    3. Run the function/create object that were just created, and with known variables


    I’m pretty sure I can figure out step one and three. It’s step two that’s giving me problems. I tried using the open() function, and eval(), but it’s giving me some problems, and that feels like a ‘janky’ way to do it.

    this is for a raspberry Pi project I’m using to control the equipment on my fish tank. The idea is I can write code for each sensor individually, and the program will automatically be able to incorporate it. I’d just have to drop it into the folder 

     

    any suggestions?

  15. I've changed it. it now works masterfully effectively.

     

     

    for (keyValue in navArray){
        $('#navMain ul').append('<li>');
        $('#navMain ul li').last().text(' ').attr('id', keyValue).append('<div>');
        $('#navMain ul li:last div').text(navArray[keyValue]);
    }
    $('#navMain ul').on('click', 'li', function(){window.location = $(this).children('div').text();});
    
  16. I didn't know that about Id's. I thought they had to be unique within their own siblings.

     

    I am making it using PNG's and CSS for two reasons

     

    1. I need unique font, and this is the best way to get it

    2. When I need to translate the page, I can have one script to change the CSS

     

    Here is how I ended up doing it, But I may change that now to have one listener like you described.

    (function( $ ){
       $.fn.navMenuADD = function(URL){$(this).click(function(){window.location = URL;});}; 
    })( jQuery );
     
    for (keyValue in navArray){
        $('#navMain ul').append('<li>');
        $('#navMain ul li').last().text(' ').attr('id', keyValue).navMenuADD(navArray[keyValue]);
    }
    
  17. so I have an object that contains the information I need to create a navbar within my CMS.

     

    I have the code working, but I feel I can make it more efficient.

     

    at the moment here is the OOO of the script:

     

    Iterate through the object and does three JQuery commands:

        1. Creates an LI object

        2. give the new LI tag a: content = ' ',  an new ID (taken from the object's key it's iterating through), and add an internal DIV;

        3. populate that new internal DIV with the URL the LI goto

        4. iterate through all the new LI's and create a 'click' listener that send the browser to that link.

     

     

    A few things should be noted.

     

       The DIV's that are created are invisible. they are just there to hold the information for the script

       This is a image based Navbar. So the LI's link to a StyleSheet. Thus the unique id

     

    I think the first and second step can be combined into one.

     

    I also feel If I could assign each LI the listener as they are being created I could make the whole thing cleaner. When I try this way, all the links end up leading to the same place. I remember this having something to do with "reference" information opposed to "String". If I remember right, When the script iterates and assigns the URL to the listener, it's not saving the information, it's saving a reference to a variable. When that variable changes, it alters all the variables that reference it. I term 'function factory" comes to mind; but a google search didn't help

     

     

    Any thoughts?

     

     

     

     

    Here is the code

     

     

     
     
        var navArray = {'navHOME' : 'index.php', 'navLOGIN' : 'login.php', 'navCART' : 'CART.php', 'navcontact' : 'contact.php'};
     
    for (keyValue in navArray){
    /*step 1 */    $('#navMain ul').append('<li>');
    /*step 2 */    $('#navMain ul li').last().text(' ').attr('id', keyValue).append('<div>');
    /*step 3 */    $('#navMain ul li:last div').attr('id', 'value').text(navArray[keyValue]);
    }
     
    /*step 4 */ $('#navMain ul > li').on('click', function(){window.location = $(this).children('div#value').text();});
    

     

     

     

  18. Hey Guys,

     

    I want to make a page on my Zencart website.

     

    I am having some trouble figuring out the best way to do it.

     

    Here is what I am hoping for:

     

    1. Looks and feels like the rest of my zencart. IE has all the themes, headers, menu items etc as the rest of the page

    2. I want to be able to edit the contents of it on my computer using my php editor, and have access to the functions and classes that come with Zencart

    3. I want to be able to place .js in the appropriate include/modules/pages subdirectory to have a link created in the <header> file 

     

    I seem to remember that I could make an ezpage, then have it reference to an internal file for content… anyone know if I am remembering right?

     

    I tried internal link, but it looks like that isn't it

  19. I am working on a website for an e-book that is available on KINDLE.

     

    I am working on a script that will send a user to the Amazon page associated with their country. it seems to be working, but I am not able to test properly because I am not able to go around the world to test the script!

     

    Is there any (free) was I can fake where my computer is so I can properly test the script?

     

    here is the code that determines where the user is coming from 

    jQuery.ajax({
        url: '//freegeoip.net/json/',
        type: 'POST',
        dataType: 'jsonp',
        success: function(location){
            window.userLocal = [];
            for(var keyy in location){
                window.userLocal[keyy] = location[keyy];
            }
        }
    });
    
  20. This is the closest section I could post this question.

     

     

    I have some fabric that I love the colour of.

     

    It's not a compels colour, it's a price if felt.

     

    Anyone have any tricks to find out what it's hex code is?

  21. OK here is what I have.

     

    Queue bf

        Function 1

        Function 2

        Function 3

        Function 4

        Function 5

     

    I want to be able to use delay to beable to set how much time is between each function.

     

    according to the jquery website .delay() should be able to do that.

     

    Don't know why it isn't.

     

    If I use SetTimeout(), I will need the clients computer to start calculating 25 different functions instead of 1 queue... isn't the best way to do it.

     

  22. Arg, setInterval is only for triggering the same function. That is not what I'm asking.

    Hurry has a built in way of queuing different functions and adding a delay between each one. The trick to doing why u want is going tO be delay. Because later on I am going to ad other functions into the queue.

     

    So setInterval is not what I need

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.